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 /Users/matti/build-worker-arm64/own-macos-arm64/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: FPATH=/opt/homebrew/share/zsh/site-functions:/usr/local/share/zsh/site-functions:/usr/share/zsh/site-functions:/usr/share/zsh/5.9/functions HOME=/Users/matti HOMEBREW_CELLAR=/opt/homebrew/Cellar HOMEBREW_PREFIX=/opt/homebrew HOMEBREW_REPOSITORY=/opt/homebrew INFOPATH=/opt/homebrew/share/info: LANG=en_US.UTF-8 LC_ADDRESS=en_AU.UTF-8 LC_IDENTIFICATION=en_AU.UTF-8 LC_MEASUREMENT=en_AU.UTF-8 LC_MONETARY=en_AU.UTF-8 LC_NAME=en_AU.UTF-8 LC_NUMERIC=en_AU.UTF-8 LC_PAPER=en_AU.UTF-8 LC_TELEPHONE=en_AU.UTF-8 LC_TIME=en_AU.UTF-8 LOGNAME=matti OLDPWD=/Users/matti PATH=/Users/matti/oss/pypy-arm64-buildbot/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Library/Frameworks/Python.framework/Versions/3.11/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin PKG_CONFIG_PATH=/opt/homebrew/Cellar/openssl@1.1/1.1.1t/lib/pkgconfig PWD=/Users/matti/build-worker-arm64/own-macos-arm64/build PYPYCHERRYPICK= PYPY_USESSION_DIR=/tmp/buildbot-arm64 PYTHONPATH=.: SHELL=/bin/zsh SHLVL=2 SSH_CLIENT=10.0.0.17 53538 22 SSH_CONNECTION=10.0.0.17 53538 10.0.0.16 22 SSH_TTY=/dev/ttys000 TERM=xterm-256color TMPDIR=/tmp/buildbot-arm64/pytest USER=matti _=/Users/matti/oss/pypy-arm64-buildbot/bin/buildslave using PTY: False using config pypy/testrunner_cfg.py using config /Users/matti/machine_cfg.py running 3 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/test_00_basic.py -- module/_hpy_universal/test/_vendored/test_argparse.py -- module/_hpy_universal/test/_vendored/test_call.py -- module/_hpy_universal/test/_vendored/test_capsule.py -- module/_hpy_universal/test/_vendored/test_capsule_legacy.py -- module/_hpy_universal/test/_vendored/test_contextvar.py -- module/_hpy_universal/test/_vendored/test_cpy_compat.py -- module/_hpy_universal/test/_vendored/test_eval.py -- module/_hpy_universal/test/_vendored/test_extra.py -- module/_hpy_universal/test/_vendored/test_helpers.py -- module/_hpy_universal/test/_vendored/test_hpybuildvalue.py -- module/_hpy_universal/test/_vendored/test_hpybytes.py -- module/_hpy_universal/test/_vendored/test_hpydict.py -- module/_hpy_universal/test/_vendored/test_hpyerr.py -- module/_hpy_universal/test/_vendored/test_hpyfield.py -- module/_hpy_universal/test/_vendored/test_hpyglobal.py -- module/_hpy_universal/test/_vendored/test_hpyimport.py -- module/_hpy_universal/test/_vendored/test_hpyiter.py -- module/_hpy_universal/test/_vendored/test_hpylist.py -- module/_hpy_universal/test/_vendored/test_hpylong.py -- module/_hpy_universal/test/_vendored/test_hpymodule.py -- module/_hpy_universal/test/_vendored/test_hpyslice.py -- module/_hpy_universal/test/_vendored/test_hpystructseq.py -- module/_hpy_universal/test/_vendored/test_hpytuple.py -- module/_hpy_universal/test/_vendored/test_hpytype.py -- module/_hpy_universal/test/_vendored/test_hpytype_legacy.py -- module/_hpy_universal/test/_vendored/test_hpyunicode.py -- module/_hpy_universal/test/_vendored/test_importing.py -- module/_hpy_universal/test/_vendored/test_legacy_forbidden.py -- module/_hpy_universal/test/_vendored/test_number.py -- module/_hpy_universal/test/_vendored/test_object.py -- module/_hpy_universal/test/_vendored/test_slots.py -- module/_hpy_universal/test/_vendored/test_slots_legacy.py -- module/_hpy_universal/test/_vendored/test_support.py -- module/_hpy_universal/test/_vendored/test_tracker.py -- 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: 178 to run ++ 05:30:16 starting config/test [1 started in total] ++ 05:30:16 starting interpreter/astcompiler/test [2 started in total] ++ 05:30:16 starting interpreter/pyparser/test [3 started in total] __ config/test [1 done in total, somefailed=False] ____________________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.py rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 162 items / 1 skipped config/test/test_pypyoption.py .................................................................................................................................................................. ==================== 162 passed, 1 skipped in 10.61 seconds ==================== ++ 05:30:28 starting interpreter/test [4 started in total] __ interpreter/pyparser/test [2 done in total, somefailed=False] ______________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.py rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 61.05 seconds ========================== ++ 05:31:22 starting module/__builtin__/test [5 started in total] __ module/__builtin__/test [3 done in total, somefailed=False] ________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 92.75 seconds ==================== ++ 05:32:57 starting module/__pypy__/test [6 started in total] __ interpreter/astcompiler/test [4 done in total, somefailed=False] ___________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.py rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 254.70 seconds ========================= ++ 05:34:37 starting module/_abc/test [7 started in total] __ module/__pypy__/test [5 done in total, somefailed=False] ___________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 99.90 seconds ===================== ++ 05:34:38 starting module/_ast/test [8 started in total] __ module/_abc/test [6 done in total, somefailed=False] _______________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 32.67 seconds =========================== ++ 05:35:15 starting module/_cffi_backend/test [9 started in total] __ module/_ast/test [7 done in total, somefailed=False] _______________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 120.63 seconds ========================== ++ 05:36:42 starting module/_codecs/test [10 started in total] __ module/_codecs/test [8 done in total, somefailed=True] _____________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 ...FF. module/_codecs/test/test_ztranslation.py . =================================== FAILURES =================================== __________ TestLocaleCodec.test_decode_locale_latin1[locale_decoder0] __________ self = <pypy.module._codecs.test.test_locale.TestLocaleCodec object at 0x000000012b538330> locale_decoder = <function str_decode_locale_surrogateescape at 0x0000000170765b50> @pytest.mark.parametrize('locale_decoder', (str_decode_locale_surrogateescape, str_decode_locale_strict)) def test_decode_locale_latin1(self, locale_decoder): self.setlocale("fr_FR") uni = u"août" string = uni.encode('latin1') > assert locale_decoder(string) == (uni.encode('utf8'), len(uni)) E assert ('ao\xed\xb3\xbbt', 4) == ('ao\xc3\xbbt', 4) E At index 0 diff: 'ao\xed\xb3\xbbt' != 'ao\xc3\xbbt' E Use -v to get the full diff module/_codecs/test/test_locale.py:77: AssertionError __________ TestLocaleCodec.test_decode_locale_latin1[locale_decoder1] __________ self = <pypy.module._codecs.test.test_locale.TestLocaleCodec object at 0x0000000159d30b80> locale_decoder = <function str_decode_locale_strict at 0x0000000170765ad8> @pytest.mark.parametrize('locale_decoder', (str_decode_locale_surrogateescape, str_decode_locale_strict)) def test_decode_locale_latin1(self, locale_decoder): self.setlocale("fr_FR") uni = u"août" string = uni.encode('latin1') > assert locale_decoder(string) == (uni.encode('utf8'), len(uni)) module/_codecs/test/test_locale.py:77: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ module/_codecs/locale.py:118: in str_decode_locale_strict errorhandler('strict', 'filesystemencoding', errmsg, s, 0, 1) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ errors = 'strict', encoding = 'filesystemencoding' msg = 'pypy_char2wchar_strict failed', s = 'ao\xfbt', startingpos = 0 endingpos = 1 def default_unicode_error_decode(errors, encoding, msg, s, startingpos, endingpos): assert endingpos >= 0 if errors == 'replace': return u'\ufffd', endingpos if errors == 'ignore': return u'', endingpos > raise UnicodeDecodeError(encoding, s, startingpos, endingpos, msg) E UnicodeDecodeError: 'filesystemencoding' codec can't decode byte 0x61 in position 0: pypy_char2wchar_strict failed ../rpython/rlib/runicode.py:107: UnicodeDecodeError =========================== short test summary info ============================ FAIL module/_codecs/test/test_locale.py::TestLocaleCodec::()::test_decode_locale_latin1[locale_decoder0] FAIL module/_codecs/test/test_locale.py::TestLocaleCodec::()::test_decode_locale_latin1[locale_decoder1] =============== 2 failed, 93 passed, 4 skipped in 139.47 seconds =============== ++ 05:39:07 starting module/_collections/test [11 started in total] __ module/_collections/test [9 done in total, somefailed=False] _______________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 74.63 seconds ========================== ++ 05:40:27 starting module/_continuation/test [12 started in total] __ module/_continuation/test [10 done in total, somefailed=False] _____________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 75.44 seconds ===================== ++ 05:41:47 starting module/_cppyy/test [13 started in total] __ module/_cppyy/test [11 done in total, somefailed=False] ____________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 0 items ========================= no tests ran in 0.00 seconds ========================= ++ 05:41:48 starting module/_csv/test [14 started in total] __ interpreter/test [12 done in total, somefailed=True] _______________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.py PYTHON3: /opt/homebrew/bin/python3.12 (Version 3.12.13 (main, Mar 3 2026, 12:39:30) [Clang 17.0.0 (clang-1700.6.3.2)]) rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 F.. 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. =================================== FAILURES =================================== _____________________ TestFSEncode.test_fsencode_fsdecode ______________________ self = <pypy.interpreter.test.test_fsencode.TestFSEncode instance at 0x0000000151498b60> def test_fsencode_fsdecode(self): space = self.space strs = [u"/home/bar/baz", u"c:\\"] if self.special_char: strs.append(self.special_char) for st in strs: # check roundtrip w_st = space.newtext(st.encode('utf8'), len(st)) w_enc = space.fsencode(w_st) w_st2 = space.fsdecode(w_enc) assert space.eq_w(w_st, w_st2) > assert space.fsdecode_w(w_enc) == st E assert 'a\xcc\x88' == u'a\u0308' E - a\xcc\x88 E + a\u0308 interpreter/test/test_fsencode.py:77: AssertionError ----------------------------- Captured stderr call ----------------------------- /Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/test/test_fsencode.py:77: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal assert space.fsdecode_w(w_enc) == st /Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/test/test_fsencode.py:1: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal import sys =========================== short test summary info ============================ FAIL interpreter/test/test_fsencode.py::TestFSEncode::()::test_fsencode_fsdecode ======== 1 failed, 1368 passed, 19 skipped, 1 xpassed in 695.61 seconds ======== ++ 05:42:08 starting module/_demo/test [15 started in total] __ module/_demo/test [13 done in total, somefailed=False] _____________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 24.81 seconds =========================== ++ 05:42:36 starting module/_hpy_universal/test/_vendored/test_00_basic.py [16 started in total] __ module/_hpy_universal/test/_vendored/test_00_basic.py [14 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:37 starting module/_hpy_universal/test/_vendored/test_argparse.py [17 started in total] __ module/_hpy_universal/test/_vendored/test_argparse.py [15 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:39 starting module/_hpy_universal/test/_vendored/test_call.py [18 started in total] __ module/_hpy_universal/test/_vendored/test_call.py [16 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:40 starting module/_hpy_universal/test/_vendored/test_capsule.py [19 started in total] __ module/_csv/test [17 done in total, somefailed=False] ______________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 50.22 seconds ========================== ++ 05:42:40 starting module/_hpy_universal/test/_vendored/test_capsule_legacy.py [20 started in total] __ module/_hpy_universal/test/_vendored/test_capsule_legacy.py [18 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:41 starting module/_hpy_universal/test/_vendored/test_contextvar.py [21 started in total] __ module/_hpy_universal/test/_vendored/test_capsule.py [19 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:41 starting module/_hpy_universal/test/_vendored/test_cpy_compat.py [22 started in total] __ module/_hpy_universal/test/_vendored/test_contextvar.py [20 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:42 starting module/_hpy_universal/test/_vendored/test_eval.py [23 started in total] __ module/_hpy_universal/test/_vendored/test_cpy_compat.py [21 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:42 starting module/_hpy_universal/test/_vendored/test_extra.py [24 started in total] __ module/_hpy_universal/test/_vendored/test_extra.py [22 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:43 starting module/_hpy_universal/test/_vendored/test_helpers.py [25 started in total] __ module/_hpy_universal/test/_vendored/test_eval.py [23 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:43 starting module/_hpy_universal/test/_vendored/test_hpybuildvalue.py [26 started in total] __ module/_hpy_universal/test/_vendored/test_helpers.py [24 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:44 starting module/_hpy_universal/test/_vendored/test_hpybytes.py [27 started in total] __ module/_hpy_universal/test/_vendored/test_hpybuildvalue.py [25 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:44 starting module/_hpy_universal/test/_vendored/test_hpydict.py [28 started in total] __ module/_hpy_universal/test/_vendored/test_hpybytes.py [26 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:45 starting module/_hpy_universal/test/_vendored/test_hpyerr.py [29 started in total] __ module/_hpy_universal/test/_vendored/test_hpydict.py [27 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:45 starting module/_hpy_universal/test/_vendored/test_hpyfield.py [30 started in total] __ module/_hpy_universal/test/_vendored/test_hpyerr.py [28 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:46 starting module/_hpy_universal/test/_vendored/test_hpyglobal.py [31 started in total] __ module/_hpy_universal/test/_vendored/test_hpyfield.py [29 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:46 starting module/_hpy_universal/test/_vendored/test_hpyimport.py [32 started in total] __ module/_hpy_universal/test/_vendored/test_hpyglobal.py [30 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:47 starting module/_hpy_universal/test/_vendored/test_hpyiter.py [33 started in total] __ module/_hpy_universal/test/_vendored/test_hpyimport.py [31 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:47 starting module/_hpy_universal/test/_vendored/test_hpylist.py [34 started in total] __ module/_hpy_universal/test/_vendored/test_hpyiter.py [32 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:48 starting module/_hpy_universal/test/_vendored/test_hpylong.py [35 started in total] __ module/_hpy_universal/test/_vendored/test_hpylist.py [33 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:48 starting module/_hpy_universal/test/_vendored/test_hpymodule.py [36 started in total] __ module/_hpy_universal/test/_vendored/test_hpylong.py [34 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:49 starting module/_hpy_universal/test/_vendored/test_hpyslice.py [37 started in total] __ module/_hpy_universal/test/_vendored/test_hpymodule.py [35 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:49 starting module/_hpy_universal/test/_vendored/test_hpystructseq.py [38 started in total] __ module/_hpy_universal/test/_vendored/test_hpyslice.py [36 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:51 starting module/_hpy_universal/test/_vendored/test_hpytuple.py [39 started in total] __ module/_hpy_universal/test/_vendored/test_hpystructseq.py [37 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:51 starting module/_hpy_universal/test/_vendored/test_hpytype.py [40 started in total] __ module/_hpy_universal/test/_vendored/test_hpytuple.py [38 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:52 starting module/_hpy_universal/test/_vendored/test_hpytype_legacy.py [41 started in total] __ module/_hpy_universal/test/_vendored/test_hpytype.py [39 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:52 starting module/_hpy_universal/test/_vendored/test_hpyunicode.py [42 started in total] __ module/_hpy_universal/test/_vendored/test_hpytype_legacy.py [40 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:53 starting module/_hpy_universal/test/_vendored/test_importing.py [43 started in total] __ module/_hpy_universal/test/_vendored/test_hpyunicode.py [41 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:53 starting module/_hpy_universal/test/_vendored/test_legacy_forbidden.py [44 started in total] __ module/_hpy_universal/test/_vendored/test_importing.py [42 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:54 starting module/_hpy_universal/test/_vendored/test_number.py [45 started in total] __ module/_hpy_universal/test/_vendored/test_legacy_forbidden.py [43 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:54 starting module/_hpy_universal/test/_vendored/test_object.py [46 started in total] __ module/_hpy_universal/test/_vendored/test_number.py [44 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:55 starting module/_hpy_universal/test/_vendored/test_slots.py [47 started in total] __ module/_hpy_universal/test/_vendored/test_object.py [45 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:55 starting module/_hpy_universal/test/_vendored/test_slots_legacy.py [48 started in total] __ module/_hpy_universal/test/_vendored/test_slots_legacy.py [46 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:56 starting module/_hpy_universal/test/_vendored/test_support.py [49 started in total] __ module/_hpy_universal/test/_vendored/test_slots.py [47 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:56 starting module/_hpy_universal/test/_vendored/test_tracker.py [50 started in total] __ module/_hpy_universal/test/_vendored/test_tracker.py [48 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:57 starting module/_hpy_universal/test/pypy [51 started in total] __ module/_hpy_universal/test/_vendored/test_support.py [49 done in total, somefailed=True] INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:57 starting module/_io/test [52 started in total] __ module/_hpy_universal/test/pypy [50 done in total, somefailed=True] ________ INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/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 "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 05:42:58 starting module/_jitlog/test [53 started in total] __ module/_jitlog/test [51 done in total, somefailed=False] ___________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 1 items module/_jitlog/test/test__jitlog.py . ========================== 1 passed in 17.15 seconds =========================== ++ 05:43:19 starting module/_locale/test [54 started in total] __ module/_locale/test [52 done in total, somefailed=False] ___________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 15 items module/_locale/test/test_locale.py ssssssssssssss. ==================== 1 passed, 14 skipped in 19.56 seconds ===================== ++ 05:43:39 starting module/_lsprof/test [55 started in total] __ module/_lsprof/test [53 done in total, somefailed=False] ___________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 6 items module/_lsprof/test/test_cprofile.py ...... ========================== 6 passed in 12.68 seconds =========================== ++ 05:43:54 starting module/_md5/test [56 started in total] __ module/_md5/test [54 done in total, somefailed=False] ______________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 8 items module/_md5/test/test_md5.py ........ ========================== 8 passed in 11.00 seconds =========================== ++ 05:44:06 starting module/_minimal_curses/test [57 started in total] __ module/_minimal_curses/test [55 done in total, somefailed=False] ___________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 6 items module/_minimal_curses/test/test_curses.py ...... ========================== 6 passed in 61.66 seconds =========================== ++ 05:45:12 starting module/_multibytecodec/test [58 started in total] __ module/_multibytecodec/test [56 done in total, somefailed=False] ___________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 56.73 seconds ===================== ++ 05:46:10 starting module/_multiprocessing/test [59 started in total] __ module/_multiprocessing/test [57 done in total, somefailed=True] ___________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 13 items module/_multiprocessing/test/test_interp_semaphore.py s module/_multiprocessing/test/test_semaphore.py .F.sssss.s module/_multiprocessing/test/test_win32.py s module/_multiprocessing/test/test_ztranslation.py . =================================== FAILURES =================================== ____________________ AppTestSemaphore.test_semaphore_basic _____________________ self = <pypy.interpreter.typedef.W_ObjectObjectUserDictWeakrefable object at 0x0000000139669130> def test_semaphore_basic(self): from _multiprocessing import SemLock import sys assert SemLock.SEM_VALUE_MAX > 10 kind = self.SEMAPHORE value = 1 maxvalue = 1 # the following line gets OSError: [Errno 38] Function not implemented # if /dev/shm is not mounted on Linux sem = SemLock(kind, value, maxvalue, "1", unlink=True) assert sem.kind == kind assert sem.maxvalue == maxvalue assert isinstance(sem.handle, int) assert sem.name is None assert sem._count() == 0 if sys.platform == 'darwin': raises(NotImplementedError, 'sem._get_value()') else: assert sem._get_value() == 1 > assert sem._is_zero() == False E (application-level) AssertionError [/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_multiprocessing/test/test_semaphore.py:35]:22: AssertionError =========================== short test summary info ============================ FAIL module/_multiprocessing/test/test_semaphore.py::AppTestSemaphore::()::test_semaphore_basic ================ 1 failed, 4 passed, 8 skipped in 28.87 seconds ================ ++ 05:46:43 starting module/_opcode/test [60 started in total] __ module/_opcode/test [58 done in total, somefailed=False] ___________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 5 items module/_opcode/test/apptest_opcode.py ..... ========================== 5 passed in 16.59 seconds =========================== ++ 05:47:00 starting module/_pickle/test [61 started in total] __ module/_cffi_backend/test [59 done in total, somefailed=True] ______________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 468 items module/_cffi_backend/test/test_c.py ..........................................................................F.....sss.s....................................................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 ...F................ 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 0x0000000123a04728>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014a282b10> 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 0x00000001431f8120> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001431f8120> 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 0x00000001238abcc8> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001238abcc8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001238abcc8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x00000001238abcc8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015b936320> 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 0x000000015b9eeb10> 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 0x102eb9680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x102eb9660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102ebd7b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000012389a6b0>, <W_TypeObject 'GenericAlias' at 0x15bd08d78>, ...] 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 0x143a8abf0> 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 0x143a8abf0> 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 0x143a8abf0> 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 0x143a8abf0> 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 0x10754cd50>> w_obj = <W_TypeObject 'ellipsis' at 0x143a8abf0> 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 0x143a8abf0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10754cd50>> 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 0x143a8abf0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10754cd50>> @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 0x10754cd50>> 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 0x10754cd50>> 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 0x0000000144a527a0>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014cab4f48> 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 0x000000014cb09560> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014cb09560> 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 0x000000014cb2cc60> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014cb2cc60> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014cb2cc60> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014cb2cc60> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014cc1ad20> 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 0x000000012493b9b8> 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 0x10494d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10494d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1049517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014cb2d360>, <W_TypeObject 'GenericAlias' at 0x15c261088>, ...] 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 0x15c2ae6b0> 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 0x15c2ae6b0> 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 0x15c2ae6b0> 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 0x15c2ae6b0> 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 0x10d74d310>> w_obj = <W_TypeObject 'ellipsis' at 0x15c2ae6b0> 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 0x15c2ae6b0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10d74d310>> 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 0x15c2ae6b0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10d74d310>> @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 0x10d74d310>> 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 0x10d74d310>> 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 0x0000000144f05268>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014ce93178> 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 0x000000014cee59e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014cee59e0> 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 0x0000000145064758> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000145064758> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000145064758> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000145064758> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001450ad460> 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 0x000000014cfe6838> 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 0x106d85680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x106d85660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x106d897b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000145064cd0>, <W_TypeObject 'GenericAlias' at 0x14d0a5050>, ...] 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 0x15cac09c0> 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 0x15cac09c0> 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 0x15cac09c0> 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 0x15cac09c0> 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 0x10758eb10>> w_obj = <W_TypeObject 'ellipsis' at 0x15cac09c0> 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 0x15cac09c0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10758eb10>> 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 0x15cac09c0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10758eb10>> @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 0x10758eb10>> 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 0x10758eb10>> 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 0x00000001259e3808>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000012632b088> 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 0x00000001453712a0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001453712a0> 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 0x0000000145392b10> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000145392b10> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000145392b10> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000145392b10> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015d57aba0> 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 0x00000001454044b8> 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 0x10794d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10794d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000145393088>, <W_TypeObject 'GenericAlias' at 0x1454d3130>, ...] 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 0x12643e100> 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 0x12643e100> 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 0x12643e100> 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 0x12643e100> 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 0x107a05f10>> w_obj = <W_TypeObject 'ellipsis' at 0x12643e100> 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 0x12643e100>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107a05f10>> 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 0x12643e100> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107a05f10>> @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 0x107a05f10>> 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 0x107a05f10>> 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 0x000000014d6cb790>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000111236408> 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 0x0000000111228960> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000111228960> 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 0x0000000111231280> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000111231280> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000111231280> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000111231280> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000111229fa0> 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 0x000000014d7e6218> 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 0x1079cd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1079cd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079d17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x00000001112317f8>, <W_TypeObject 'GenericAlias' at 0x15e3f64f0>, ...] 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 0x1269362c0> 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 0x1269362c0> 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 0x1269362c0> 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 0x1269362c0> 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 0x1078a9b80>> w_obj = <W_TypeObject 'ellipsis' at 0x1269362c0> 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 0x1269362c0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1078a9b80>> 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 0x1269362c0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1078a9b80>> @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 0x1078a9b80>> 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 0x1078a9b80>> 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 0x000000014b845c40>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x00000001436058f8> 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 0x0000000123e964e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000123e964e0> 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 0x0000000123e9c1e0> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000123e9c1e0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000123e9c1e0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000123e9c1e0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000123e97c20> 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 0x000000015b87b0c0> 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 0x10494d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10494d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1049517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000123e9c758>, <W_TypeObject 'GenericAlias' at 0x14bb13248>, ...] 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 0x15c2bead8> 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 0x15c2bead8> 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 0x15c2bead8> 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 0x15c2bead8> 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 0x107525f60>> w_obj = <W_TypeObject 'ellipsis' at 0x15c2bead8> 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 0x15c2bead8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107525f60>> 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 0x15c2bead8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107525f60>> @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 0x107525f60>> 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 0x107525f60>> 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 0x0000000124516980>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014ce93448> 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 0x000000015d800420> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015d800420> 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 0x000000015d7fcc28> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015d7fcc28> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015d7fcc28> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000015d7fcc28> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015d801b60> 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 0x0000000124863980> 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 0x106d85680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x106d85660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x106d897b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000015d7fd1a0>, <W_TypeObject 'GenericAlias' at 0x1264fc170>, ...] 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 0x14cd11948> 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 0x14cd11948> 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 0x14cd11948> 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 0x14cd11948> 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 0x1074f98e0>> w_obj = <W_TypeObject 'ellipsis' at 0x14cd11948> 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 0x14cd11948>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1074f98e0>> 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 0x14cd11948> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1074f98e0>> @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 0x1074f98e0>> 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 0x1074f98e0>> 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 0x000000014cfec110>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x00000001268110b0> 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 0x00000001259281e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001259281e0> 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 0x0000000125915bb0> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000125915bb0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000125915bb0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000125915bb0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000125929860> 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 0x000000014564af00> 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 0x10794d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10794d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000125964170>, <W_TypeObject 'GenericAlias' at 0x15c5ff168>, ...] 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 0x1605269c0> 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 0x1605269c0> 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 0x1605269c0> 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 0x1605269c0> 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 0x1078ac9e0>> w_obj = <W_TypeObject 'ellipsis' at 0x1605269c0> 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 0x1605269c0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1078ac9e0>> 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 0x1605269c0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1078ac9e0>> @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 0x1078ac9e0>> 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 0x1078ac9e0>> 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 0x000000014d798020>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014c9b73d0> 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 0x000000014ca33760> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014ca33760> 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 0x000000014d93b2b8> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014d93b2b8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014d93b2b8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014d93b2b8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000012628f120> 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 0x000000014da91718> 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 0x107b4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107b4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107b517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014d93b830>, <W_TypeObject 'GenericAlias' at 0x14dbe88a8>, ...] 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 0x14dc2bde0> 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 0x14dc2bde0> 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 0x14dc2bde0> 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 0x14dc2bde0> 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 0x1077798e0>> w_obj = <W_TypeObject 'ellipsis' at 0x14dc2bde0> 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 0x14dc2bde0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1077798e0>> 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 0x14dc2bde0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1077798e0>> @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 0x1077798e0>> 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 0x1077798e0>> 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 0x0000000125814278>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x00000001258482f0> 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 0x0000000125844d60> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000125844d60> 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 0x0000000125841050> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000125841050> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000125841050> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000125841050> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000145f463e0> 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 0x00000001258d49f8> 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 0x107bcd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107bcd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107bd17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x00000001258415c8>, <W_TypeObject 'GenericAlias' at 0x16096d1a0>, ...] 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 0x14e994138> 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 0x14e994138> 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 0x14e994138> 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 0x14e994138> 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 0x10726c510>> w_obj = <W_TypeObject 'ellipsis' at 0x14e994138> 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 0x14e994138>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10726c510>> 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 0x14e994138> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10726c510>> @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 0x10726c510>> 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 0x10726c510>> 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 0x00000001468324d0>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x00000001274e55b0> 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 0x000000012759a7e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000012759a7e0> 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 0x0000000127597600> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000127597600> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000127597600> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000127597600> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015c8eee20> 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 0x000000015ddc7210> 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 0x107d4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107d4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107d517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000127597b78>, <W_TypeObject 'GenericAlias' at 0x146ccb440>, ...] 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 0x146d204f0> 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 0x146d204f0> 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 0x146d204f0> 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 0x146d204f0> 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 0x107c90380>> w_obj = <W_TypeObject 'ellipsis' at 0x146d204f0> 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 0x146d204f0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107c90380>> 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 0x146d204f0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107c90380>> @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 0x107c90380>> 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 0x107c90380>> 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 0x0000000127ac1b50>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014df47a88> 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 0x0000000124396e20> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000124396e20> 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 0x000000015e66def8> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015e66def8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015e66def8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000015e66def8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001243c6960> 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 0x000000015b1ee1a8> 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 0x10494d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10494d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1049517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000126936758>, <W_TypeObject 'GenericAlias' at 0x124106d40>, ...] 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 0x15b7d3018> 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 0x15b7d3018> 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 0x15b7d3018> 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 0x15b7d3018> 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 0x10738ba60>> w_obj = <W_TypeObject 'ellipsis' at 0x15b7d3018> 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 0x15b7d3018>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10738ba60>> 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 0x15b7d3018> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10738ba60>> @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 0x10738ba60>> 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 0x10738ba60>> 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 0x000000015ba3b970>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000123de6de0> 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 0x0000000145d3afe0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000145d3afe0> 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 0x000000014b5cb9b8> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014b5cb9b8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014b5cb9b8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014b5cb9b8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000012515a7a0> 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 0x000000015b819bb0> 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 0x106d85680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x106d85660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x106d897b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014b5cbf30>, <W_TypeObject 'GenericAlias' at 0x12654e330>, ...] 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 0x16092f558> 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 0x16092f558> 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 0x16092f558> 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 0x16092f558> 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 0x10764fe70>> w_obj = <W_TypeObject 'ellipsis' at 0x16092f558> 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 0x16092f558>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10764fe70>> 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 0x16092f558> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10764fe70>> @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 0x10764fe70>> 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 0x10764fe70>> 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 0x0000000130fb7f10>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014d7516f0> 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 0x000000015c9ceae0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015c9ceae0> 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 0x000000015c9a6288> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015c9a6288> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015c9a6288> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000015c9a6288> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001448c4320> 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 0x000000014492b718> 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 0x10794d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10794d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000015c9a6800>, <W_TypeObject 'GenericAlias' at 0x14c95d8a0>, ...] 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 0x14c994ec8> 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 0x14c994ec8> 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 0x14c994ec8> 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 0x14c994ec8> 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 0x10766e640>> w_obj = <W_TypeObject 'ellipsis' at 0x14c994ec8> 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 0x14c994ec8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10766e640>> 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 0x14c994ec8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10766e640>> @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 0x10766e640>> 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 0x10766e640>> 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 0x000000014d798908>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000127832020> 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 0x000000014d12ec20> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014d12ec20> 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 0x0000000126a47750> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000126a47750> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000126a47750> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000126a47750> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000144ffa2a0> 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 0x0000000146f9b718> 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 0x1079cd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1079cd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079d17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000126a478d8>, <W_TypeObject 'GenericAlias' at 0x14e86a640>, ...] 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 0x14e8b7b40> 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 0x14e8b7b40> 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 0x14e8b7b40> 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 0x14e8b7b40> 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 0x10768e260>> w_obj = <W_TypeObject 'ellipsis' at 0x14e8b7b40> 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 0x14e8b7b40>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10768e260>> 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 0x14e8b7b40> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10768e260>> @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 0x10768e260>> 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 0x10768e260>> 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 0x00000001468329f8>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000125c7ad68> 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 0x00000001503dd020> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001503dd020> 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 0x0000000125c6d360> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000125c6d360> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000125c6d360> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000125c6d360> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001110a6760> 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 0x000000014e823910> 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 0x107b4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107b4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107b517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000125c6d8d8>, <W_TypeObject 'GenericAlias' at 0x15dd88988>, ...] 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 0x15c3ae950> 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 0x15c3ae950> 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 0x15c3ae950> 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 0x15c3ae950> 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 0x1077ff5e0>> w_obj = <W_TypeObject 'ellipsis' at 0x15c3ae950> 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 0x15c3ae950>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1077ff5e0>> 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 0x15c3ae950> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1077ff5e0>> @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 0x1077ff5e0>> 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 0x1077ff5e0>> 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 0x0000000146ae5100>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000144704d90> 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 0x000000015da34ce0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015da34ce0> 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 0x000000015da57868> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015da57868> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015da57868> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000015da57868> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000146a66f20> 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 0x0000000145b6a170> 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 0x107bcd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107bcd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107bd17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014717c250>, <W_TypeObject 'GenericAlias' at 0x125d70720>, ...] 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 0x125da5c58> 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 0x125da5c58> 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 0x125da5c58> 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 0x125da5c58> 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 0x107c78b60>> w_obj = <W_TypeObject 'ellipsis' at 0x125da5c58> 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 0x125da5c58>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107c78b60>> 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 0x125da5c58> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107c78b60>> @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 0x107c78b60>> 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 0x107c78b60>> 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 0x000000015c043c40>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014773ef48> 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 0x0000000147777820> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000147777820> 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 0x0000000126ab6790> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000126ab6790> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000126ab6790> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000126ab6790> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000147777c20> 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 0x000000014e9716a8> 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 0x10494d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10494d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1049517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000126ab6d08>, <W_TypeObject 'GenericAlias' at 0x14b71ad08>, ...] 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 0x14b754218> 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 0x14b754218> 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 0x14b754218> 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 0x14b754218> 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 0x11d69ef00>> w_obj = <W_TypeObject 'ellipsis' at 0x14b754218> 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 0x14b754218>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11d69ef00>> 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 0x14b754218> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11d69ef00>> @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 0x11d69ef00>> 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 0x11d69ef00>> 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 0x000000015b989cb8>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000123be23b8> 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 0x000000015ca592e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015ca592e0> 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 0x0000000110d8d910> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000110d8d910> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000110d8d910> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000110d8d910> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015c650b60> 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 0x000000014b5963d8> 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 0x106d85680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x106d85660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x106d897b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000110d8dec0>, <W_TypeObject 'GenericAlias' at 0x123997e50>, ...] 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 0x1238efcc8> 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 0x1238efcc8> 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 0x1238efcc8> 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 0x1238efcc8> 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 0x1072358e0>> w_obj = <W_TypeObject 'ellipsis' at 0x1238efcc8> 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 0x1238efcc8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1072358e0>> 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 0x1238efcc8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1072358e0>> @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 0x1072358e0>> 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 0x1072358e0>> 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 0x0000000130fb6980>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000015c63fd08> 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 0x000000014d588ae0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014d588ae0> 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 0x000000013142d168> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000013142d168> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000013142d168> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000013142d168> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014d5ae360> 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 0x000000015d5335c8> 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 0x10794d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10794d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000013142d6e0>, <W_TypeObject 'GenericAlias' at 0x145e7e218>, ...] 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 0x145e85520> 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 0x145e85520> 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 0x145e85520> 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 0x145e85520> 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 0x1078d9960>> w_obj = <W_TypeObject 'ellipsis' at 0x145e85520> 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 0x145e85520>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1078d9960>> 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 0x145e85520> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1078d9960>> @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 0x1078d9960>> 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 0x1078d9960>> 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 0x000000014d798ea8>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000012504b448> 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 0x0000000145df5260> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000145df5260> 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 0x000000015d7ae1e0> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015d7ae1e0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015d7ae1e0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000015d7ae1e0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000012480cc60> 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 0x000000014cf03478> 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 0x1079cd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1079cd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079d17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000015d7ae758>, <W_TypeObject 'GenericAlias' at 0x15c2f7ad0>, ...] 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 0x15d906fe0> 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 0x15d906fe0> 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 0x15d906fe0> 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 0x15d906fe0> 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 0x10787e850>> w_obj = <W_TypeObject 'ellipsis' at 0x15d906fe0> 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 0x15d906fe0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10787e850>> 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 0x15d906fe0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10787e850>> @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 0x10787e850>> 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 0x10787e850>> 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 0x000000015ddd8e30>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000144d73fd8> 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 0x000000014deadaa0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014deadaa0> 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 0x000000014cbd0368> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014cbd0368> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014cbd0368> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014cbd0368> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014ec25260> 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 0x000000014e4eb3d0> 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 0x107b4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107b4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107b517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014cbd08e0>, <W_TypeObject 'GenericAlias' at 0x110c3e058>, ...] 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 0x1254a7360> 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 0x1254a7360> 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 0x1254a7360> 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 0x1254a7360> 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 0x107685a20>> w_obj = <W_TypeObject 'ellipsis' at 0x1254a7360> 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 0x1254a7360>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107685a20>> 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 0x1254a7360> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107685a20>> @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 0x107685a20>> 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 0x107685a20>> 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 0x000000015c043ad8>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000015cf6d3a8> 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 0x000000014dd7fca0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014dd7fca0> 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 0x0000000110f80560> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000110f80560> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000110f80560> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000110f80560> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000146efb360> 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 0x000000014dddca68> 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 0x107d4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107d4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107d517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000110f80ad8>, <W_TypeObject 'GenericAlias' at 0x14455d168>, ...] 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 0x14e0080c8> 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 0x14e0080c8> 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 0x14e0080c8> 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 0x14e0080c8> 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 0x1076f30e0>> w_obj = <W_TypeObject 'ellipsis' at 0x14e0080c8> 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 0x14e0080c8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1076f30e0>> 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 0x14e0080c8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1076f30e0>> @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 0x1076f30e0>> 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 0x1076f30e0>> 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 0x0000000127400200>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000013152f650> 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 0x000000015d55e020> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015d55e020> 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 0x000000015c3b44b8> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015c3b44b8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015c3b44b8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000015c3b44b8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000127467ca0> 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 0x000000014eb7b0c0> 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 0x10494d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10494d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1049517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x00000001310ea170>, <W_TypeObject 'GenericAlias' at 0x14b755868>, ...] 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 0x130cbd8a0> 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 0x130cbd8a0> 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 0x130cbd8a0> 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 0x130cbd8a0> 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 0x1070ecc50>> w_obj = <W_TypeObject 'ellipsis' at 0x130cbd8a0> 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 0x130cbd8a0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1070ecc50>> 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 0x130cbd8a0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1070ecc50>> @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 0x1070ecc50>> 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 0x1070ecc50>> 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 0x000000015ba3a638>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000123dbc570> 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 0x0000000125f3f4a0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000125f3f4a0> 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 0x000000014c7732b8> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014c7732b8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014c7732b8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014c7732b8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000125f531a0> 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 0x000000014459c608> 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 0x106d85680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x106d85660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x106d897b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014c773830>, <W_TypeObject 'GenericAlias' at 0x15b1079b8>, ...] 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 0x15b21ca30> 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 0x15b21ca30> 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 0x15b21ca30> 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 0x15b21ca30> 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 0x1076cb740>> w_obj = <W_TypeObject 'ellipsis' at 0x15b21ca30> 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 0x15b21ca30>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1076cb740>> 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 0x15b21ca30> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1076cb740>> @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 0x1076cb740>> 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 0x1076cb740>> 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 0x000000014cfec368>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014ce3f178> 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 0x000000014dbc58a0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014dbc58a0> 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 0x000000015bbc0e58> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015bbc0e58> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015bbc0e58> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000015bbc0e58> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001444c72e0> 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 0x0000000126e00330> 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 0x10794d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10794d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000015bbc13d0>, <W_TypeObject 'GenericAlias' at 0x12700aec8>, ...] 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 0x126ff09c0> 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 0x126ff09c0> 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 0x126ff09c0> 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 0x126ff09c0> 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 0x1074e1f20>> w_obj = <W_TypeObject 'ellipsis' at 0x126ff09c0> 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 0x126ff09c0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1074e1f20>> 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 0x126ff09c0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1074e1f20>> @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 0x1074e1f20>> 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 0x1074e1f20>> 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 0x000000014d7f1808>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x00000001454e62a0> 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 0x0000000127a987a0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000127a987a0> 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 0x0000000127a74bf0> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000127a74bf0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000127a74bf0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000127a74bf0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000127a99f20> 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 0x0000000146c83be8> 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 0x1079cd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1079cd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079d17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000127a75168>, <W_TypeObject 'GenericAlias' at 0x14f30de50>, ...] 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 0x14f2fbcc8> 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 0x14f2fbcc8> 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 0x14f2fbcc8> 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 0x14f2fbcc8> 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 0x11d6c0950>> w_obj = <W_TypeObject 'ellipsis' at 0x14f2fbcc8> 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 0x14f2fbcc8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11d6c0950>> 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 0x14f2fbcc8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11d6c0950>> @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 0x11d6c0950>> 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 0x11d6c0950>> 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 0x000000014e81cb60>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000130e45ba0> 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 0x0000000146e12f20> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000146e12f20> 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 0x0000000146e75bb0> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000146e75bb0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000146e75bb0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000146e75bb0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000111268d20> 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 0x000000014696f7f8> 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 0x107b4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107b4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107b517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000015d3dc170>, <W_TypeObject 'GenericAlias' at 0x14cc74a68>, ...] 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 0x14cc5c6e8> 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 0x14cc5c6e8> 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 0x14cc5c6e8> 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 0x14cc5c6e8> 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 0x1077b5a20>> w_obj = <W_TypeObject 'ellipsis' at 0x14cc5c6e8> 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 0x14cc5c6e8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1077b5a20>> 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 0x14cc5c6e8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1077b5a20>> @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 0x1077b5a20>> 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 0x1077b5a20>> 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 0x00000001608e16a0>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014e9e43e0> 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 0x000000014ea35860> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014ea35860> 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 0x000000014e9bc6b0> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014e9bc6b0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014e9bc6b0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014e9bc6b0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000012728f020> 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 0x0000000110d85868> 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 0x107bcd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107bcd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107bd17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014e9bcc28>, <W_TypeObject 'GenericAlias' at 0x15c007948>, ...] 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 0x14e476ec8> 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 0x14e476ec8> 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 0x14e476ec8> 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 0x14e476ec8> 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 0x107e69720>> w_obj = <W_TypeObject 'ellipsis' at 0x14e476ec8> 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 0x14e476ec8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107e69720>> 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 0x14e476ec8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107e69720>> @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 0x107e69720>> 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 0x107e69720>> 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 0x0000000143b0bc40>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000147977240> 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 0x00000001479f3220> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001479f3220> 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 0x000000014f0b84f0> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014f0b84f0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014f0b84f0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014f0b84f0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014f252a60> 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 0x0000000125854758> 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 0x10494d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10494d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1049517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014f0b8a68>, <W_TypeObject 'GenericAlias' at 0x14b6fb7f8>, ...] 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 0x14b737e50> 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 0x14b737e50> 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 0x14b737e50> 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 0x14b737e50> 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 0x1071b3fd0>> w_obj = <W_TypeObject 'ellipsis' at 0x14b737e50> 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 0x14b737e50>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1071b3fd0>> 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 0x14b737e50> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1071b3fd0>> @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 0x1071b3fd0>> 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 0x1071b3fd0>> 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 0x000000015b988020>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000123bcf4c0> 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 0x0000000144df61e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000144df61e0> 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 0x000000014e5ae720> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014e5ae720> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014e5ae720> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014e5ae720> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000144df7c60> 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 0x00000001260f7ec0> 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 0x106d85680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x106d85660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x106d897b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014e5aec98>, <W_TypeObject 'GenericAlias' at 0x14d415478>, ...] 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 0x110de7cc8> 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 0x110de7cc8> 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 0x110de7cc8> 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 0x110de7cc8> 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 0x107493a50>> w_obj = <W_TypeObject 'ellipsis' at 0x110de7cc8> 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 0x110de7cc8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107493a50>> 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 0x110de7cc8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107493a50>> @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 0x107493a50>> 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 0x107493a50>> 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 0x0000000144f04728>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014ce3eea8> 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 0x0000000126dc1c20> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000126dc1c20> 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 0x0000000145e241a8> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000145e241a8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000145e241a8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000145e241a8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000126dd76e0> 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 0x000000015c377168> 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 0x10794d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10794d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000145e24720>, <W_TypeObject 'GenericAlias' at 0x14ba1ca68>, ...] 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 0x14543c6b0> 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 0x14543c6b0> 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 0x14543c6b0> 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 0x14543c6b0> 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 0x107ac56f0>> w_obj = <W_TypeObject 'ellipsis' at 0x14543c6b0> 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 0x14543c6b0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107ac56f0>> 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 0x14543c6b0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107ac56f0>> @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 0x107ac56f0>> 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 0x107ac56f0>> 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 0x000000014d7f1808>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000160980c00> 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 0x00000001449fb5e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001449fb5e0> 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 0x00000001449fda60> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001449fda60> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001449fda60> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x00000001449fda60> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015e3d4e20> 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 0x000000012601ce58> 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 0x1079cd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1079cd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079d17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000160504020>, <W_TypeObject 'GenericAlias' at 0x14e426870>, ...] 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 0x14e416918> 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 0x14e416918> 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 0x14e416918> 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 0x14e416918> 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 0x107cce350>> w_obj = <W_TypeObject 'ellipsis' at 0x14e416918> 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 0x14e416918>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107cce350>> 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 0x14e416918> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107cce350>> @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 0x107cce350>> 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 0x107cce350>> 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 0x000000015cbd6f98>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014659e368> 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 0x00000001462062e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001462062e0> 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 0x0000000125865de0> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000125865de0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000125865de0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000125865de0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001462078e0> 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 0x000000015ca40bb8> 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 0x107b4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107b4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107b517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x00000001461a43a0>, <W_TypeObject 'GenericAlias' at 0x160603050>, ...] 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 0x16061e800> 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 0x16061e800> 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 0x16061e800> 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 0x16061e800> 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 0x1076a0fe0>> w_obj = <W_TypeObject 'ellipsis' at 0x16061e800> 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 0x16061e800>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1076a0fe0>> 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 0x16061e800> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1076a0fe0>> @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 0x1076a0fe0>> 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 0x1076a0fe0>> 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 0x0000000144cdf088>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014cfb50b0> 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 0x000000012769a660> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000012769a660> 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 0x0000000127691b40> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000127691b40> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000127691b40> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000127691b40> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000012769bda0> 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 0x0000000145a0a790> 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 0x107d4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107d4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107d517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000012719a100>, <W_TypeObject 'GenericAlias' at 0x14ded0e58>, ...] 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 0x15cb0ab80> 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 0x15cb0ab80> 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 0x15cb0ab80> 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 0x15cb0ab80> 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 0x107860cc0>> w_obj = <W_TypeObject 'ellipsis' at 0x15cb0ab80> 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 0x15cb0ab80>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107860cc0>> 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 0x15cb0ab80> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107860cc0>> @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 0x107860cc0>> 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 0x107860cc0>> 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 0x000000015b5a8200>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x00000001110b25e8> 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 0x000000014ee26960> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014ee26960> 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 0x0000000146ed0058> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000146ed0058> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000146ed0058> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000146ed0058> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014e34c3a0> 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 0x000000014e870fe0> 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 0x10494d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10494d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1049517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x00000001477c88a8>, <W_TypeObject 'GenericAlias' at 0x14b71a6e8>, ...] 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 0x14b754838> 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 0x14b754838> 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 0x14b754838> 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 0x14b754838> 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 0x1071c2120>> w_obj = <W_TypeObject 'ellipsis' at 0x14b754838> 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 0x14b754838>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1071c2120>> 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 0x14b754838> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1071c2120>> @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 0x1071c2120>> 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 0x1071c2120>> 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 0x000000015b9ec728>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014b929cb8> 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 0x000000015d2e4f20> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015d2e4f20> 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 0x0000000146891da8> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000146891da8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000146891da8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000146891da8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015d2eeaa0> 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 0x000000012633d0c0> 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 0x106d85680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x106d85660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x106d897b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000015d194480>, <W_TypeObject 'GenericAlias' at 0x110dd7590>, ...] 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 0x14e8b98a0> 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 0x14e8b98a0> 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 0x14e8b98a0> 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 0x14e8b98a0> 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 0x107592920>> w_obj = <W_TypeObject 'ellipsis' at 0x14e8b98a0> 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 0x14e8b98a0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107592920>> 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 0x14e8b98a0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107592920>> @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 0x107592920>> 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 0x107592920>> 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 0x000000014d00e548>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000015c63ea98> 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 0x00000001463a60a0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001463a60a0> 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 0x000000015d020fe0> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015d020fe0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015d020fe0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000015d020fe0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001463a78e0> 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 0x000000014f3d9b08> 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 0x10794d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10794d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000015d021558>, <W_TypeObject 'GenericAlias' at 0x123e122f8>, ...] 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 0x123e36330> 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 0x123e36330> 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 0x123e36330> 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 0x123e36330> 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 0x1075c0e40>> w_obj = <W_TypeObject 'ellipsis' at 0x123e36330> 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 0x123e36330>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1075c0e40>> 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 0x123e36330> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1075c0e40>> @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 0x1075c0e40>> 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 0x1075c0e40>> 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 0x000000014daadbc8>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014d59d1a0> 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 0x0000000146083960> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000146083960> 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 0x000000015bdce9f8> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015bdce9f8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015bdce9f8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000015bdce9f8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015d10b520> 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 0x000000015b57f8a0> 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 0x1079cd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1079cd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079d17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000015bdcef70>, <W_TypeObject 'GenericAlias' at 0x14e45fd38>, ...] 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 0x145013bb0> 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 0x145013bb0> 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 0x145013bb0> 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 0x145013bb0> 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 0x1075d2e40>> w_obj = <W_TypeObject 'ellipsis' at 0x145013bb0> 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 0x145013bb0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1075d2e40>> 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 0x145013bb0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1075d2e40>> @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 0x1075d2e40>> 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 0x1075d2e40>> 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 0x0000000145b4d088>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000015d6df3a8> 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 0x000000012795b820> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000012795b820> 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 0x000000013111e250> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000013111e250> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000013111e250> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000013111e250> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000124e0b060> 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 0x000000015c153280> 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 0x107b4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107b4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107b517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000013111e7c8>, <W_TypeObject 'GenericAlias' at 0x15dd4ab80>, ...] 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 0x14ee62aa0> 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 0x14ee62aa0> 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 0x14ee62aa0> 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 0x14ee62aa0> 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 0x1075e4f10>> w_obj = <W_TypeObject 'ellipsis' at 0x14ee62aa0> 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 0x14ee62aa0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1075e4f10>> 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 0x14ee62aa0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1075e4f10>> @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 0x1075e4f10>> 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 0x1075e4f10>> 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 0x0000000110dc0b60>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014d680660> 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 0x000000014d6703a0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014d6703a0> 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 0x000000014d6a55c8> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014d6a55c8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014d6a55c8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014d6a55c8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014d6719e0> 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 0x0000000144879408> 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 0x107bcd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107bcd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107bd17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014d6a5b40>, <W_TypeObject 'GenericAlias' at 0x124bd0720>, ...] 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 0x14c736288> 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 0x14c736288> 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 0x14c736288> 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 0x14c736288> 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 0x107a7f530>> w_obj = <W_TypeObject 'ellipsis' at 0x14c736288> 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 0x14c736288>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107a7f530>> 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 0x14c736288> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107a7f530>> @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 0x107a7f530>> 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 0x107a7f530>> 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 0x000000012725f178>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000015c77f268> 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 0x000000015c7e5860> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015c7e5860> 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 0x0000000145c4f9f0> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000145c4f9f0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000145c4f9f0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000145c4f9f0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000131692d20> 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 0x000000014deffd00> 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 0x10494d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10494d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1049517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000145c4ff68>, <W_TypeObject 'GenericAlias' at 0x14b6b7360>, ...] 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 0x14b6f4b80> 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 0x14b6f4b80> 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 0x14b6f4b80> 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 0x14b6f4b80> 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 0x10737f170>> w_obj = <W_TypeObject 'ellipsis' at 0x14b6f4b80> 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 0x14b6f4b80>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10737f170>> 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 0x14b6f4b80> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10737f170>> @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 0x10737f170>> 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 0x10737f170>> 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 0x000000015ba1a638>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014b835650> 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 0x000000015d800060> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015d800060> 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 0x0000000126612c98> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000126612c98> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000126612c98> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000126612c98> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015d8017a0> 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 0x000000014e5aed78> 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 0x106d85680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x106d85660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x106d897b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x00000001266133d0>, <W_TypeObject 'GenericAlias' at 0x14ecbc4b8>, ...] 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 0x160a6efa8> 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 0x160a6efa8> 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 0x160a6efa8> 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 0x160a6efa8> 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 0x11d6a4e70>> w_obj = <W_TypeObject 'ellipsis' at 0x160a6efa8> 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 0x160a6efa8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11d6a4e70>> 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 0x160a6efa8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11d6a4e70>> @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 0x11d6a4e70>> 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 0x11d6a4e70>> 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 0x000000014d05ebd8>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000015bf6eca0> 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 0x000000014e12e5e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014e12e5e0> 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 0x000000014d6d6790> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014d6d6790> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014d6d6790> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014d6d6790> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014d588060> 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 0x000000014453f8d8> 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 0x10794d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10794d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014d6d6d08>, <W_TypeObject 'GenericAlias' at 0x15daf6fa8>, ...] 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 0x146c763a0> 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 0x146c763a0> 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 0x146c763a0> 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 0x146c763a0> 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 0x10770e080>> w_obj = <W_TypeObject 'ellipsis' at 0x146c763a0> 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 0x146c763a0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10770e080>> 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 0x146c763a0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10770e080>> @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 0x10770e080>> 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 0x10770e080>> 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 0x0000000145d82f20>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000015dc46908> 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 0x000000014de9d1e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014de9d1e0> 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 0x000000015bdb7b08> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015bdb7b08> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015bdb7b08> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000015bdb7b08> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000146054be0> 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 0x0000000145d87398> 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 0x1079cd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1079cd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079d17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x00000001453360c8>, <W_TypeObject 'GenericAlias' at 0x15c33a020>, ...] 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 0x14cadc0c8> 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 0x14cadc0c8> 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 0x14cadc0c8> 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 0x14cadc0c8> 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 0x107227dc0>> w_obj = <W_TypeObject 'ellipsis' at 0x14cadc0c8> 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 0x14cadc0c8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107227dc0>> 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 0x14cadc0c8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107227dc0>> @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 0x107227dc0>> 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 0x107227dc0>> 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 0x0000000145b81808>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014655a7a0> 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 0x0000000144e889e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000144e889e0> 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 0x0000000144ebf440> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000144ebf440> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000144ebf440> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000144ebf440> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015d496160> 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 0x000000015d447d70> 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 0x107b4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107b4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107b517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000144ebfad0>, <W_TypeObject 'GenericAlias' at 0x14de8da60>, ...] 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 0x14de650c0> 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 0x14de650c0> 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 0x14de650c0> 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 0x14de650c0> 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 0x107edca10>> w_obj = <W_TypeObject 'ellipsis' at 0x14de650c0> 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 0x14de650c0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107edca10>> 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 0x14de650c0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107edca10>> @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 0x107edca10>> 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 0x107edca10>> 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 0x0000000150194200>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000015c3e7f38> 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 0x000000014ec4dc60> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014ec4dc60> 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 0x000000014ec9fc90> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014ec9fc90> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014ec9fc90> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014ec9fc90> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014e9d12e0> 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 0x0000000147703c58> 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 0x107d4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107d4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107d517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000147556250>, <W_TypeObject 'GenericAlias' at 0x15e21ac98>, ...] 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 0x1110aab48> 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 0x1110aab48> 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 0x1110aab48> 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 0x1110aab48> 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 0x107c0e060>> w_obj = <W_TypeObject 'ellipsis' at 0x1110aab48> 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 0x1110aab48>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107c0e060>> 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 0x1110aab48> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107c0e060>> @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 0x107c0e060>> 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 0x107c0e060>> 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 0x00000001313dfda8>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x00000001475c9da8> 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 0x000000014789bb60> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014789bb60> 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 0x0000000125093a60> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000125093a60> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000125093a60> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000125093a60> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015c7e54e0> 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 0x0000000125166720> 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 0x10494d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10494d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1049517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000145fe4020>, <W_TypeObject 'GenericAlias' at 0x14b6b7fa0>, ...] 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 0x14b6f5210> 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 0x14b6f5210> 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 0x14b6f5210> 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 0x14b6f5210> 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 0x1072373d0>> w_obj = <W_TypeObject 'ellipsis' at 0x14b6f5210> 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 0x14b6f5210>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1072373d0>> 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 0x14b6f5210> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1072373d0>> @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 0x1072373d0>> 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 0x1072373d0>> 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 0x000000015b9ecf20>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014b835d30> 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 0x0000000124d11160> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000124d11160> 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 0x0000000126612368> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000126612368> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000126612368> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000126612368> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015c17eba0> 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 0x000000014e5af7f8> 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 0x106d85680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x106d85660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x106d897b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x00000001266128e0>, <W_TypeObject 'GenericAlias' at 0x14ed0e5d0>, ...] 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 0x14e8bd328> 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 0x14e8bd328> 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 0x14e8bd328> 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 0x14e8bd328> 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 0x1073d08c0>> w_obj = <W_TypeObject 'ellipsis' at 0x14e8bd328> 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 0x14e8bd328>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1073d08c0>> 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 0x14e8bd328> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1073d08c0>> @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 0x1073d08c0>> 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 0x1073d08c0>> 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 0x000000014d05ff88>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014d750598> 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 0x0000000126da62e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000126da62e0> 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 0x000000015e687cc8> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015e687cc8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015e687cc8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000015e687cc8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000126da7e20> 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 0x000000015d480918> 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 0x10794d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10794d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000015e65a288>, <W_TypeObject 'GenericAlias' at 0x15b925638>, ...] 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 0x15b8e6d78> 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 0x15b8e6d78> 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 0x15b8e6d78> 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 0x15b8e6d78> 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 0x1073e6a60>> w_obj = <W_TypeObject 'ellipsis' at 0x15b8e6d78> 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 0x15b8e6d78>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1073e6a60>> 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 0x15b8e6d78> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1073e6a60>> @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 0x1073e6a60>> 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 0x1073e6a60>> 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 0x00000001258e45c0>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014cc582c8> 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 0x0000000125763e20> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000125763e20> 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 0x0000000125495b78> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000125495b78> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000125495b78> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000125495b78> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000012577d520> 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 0x000000014e89c480> 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 0x1079cd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1079cd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079d17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000013101e138>, <W_TypeObject 'GenericAlias' at 0x1450d6b80>, ...] 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 0x1450ce288> 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 0x1450ce288> 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 0x1450ce288> 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 0x1450ce288> 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 0x107ebffa0>> w_obj = <W_TypeObject 'ellipsis' at 0x1450ce288> 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 0x1450ce288>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107ebffa0>> 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 0x1450ce288> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107ebffa0>> @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 0x107ebffa0>> 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 0x107ebffa0>> 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 0x000000015c042110>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000125711dd0> 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 0x0000000144e703e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000144e703e0> 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 0x0000000144eb1440> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000144eb1440> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000144eb1440> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000144eb1440> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000144e71ca0> 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 0x000000015cb5f478> 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 0x107b4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107b4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107b517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000144eb19b8>, <W_TypeObject 'GenericAlias' at 0x15c104800>, ...] 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 0x15c1188a8> 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 0x15c1188a8> 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 0x15c1188a8> 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 0x15c1188a8> 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 0x1075725f0>> w_obj = <W_TypeObject 'ellipsis' at 0x15c1188a8> 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 0x15c1188a8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1075725f0>> 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 0x15c1188a8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1075725f0>> @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 0x1075725f0>> 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 0x1075725f0>> 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 0x0000000143bdc9f8>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000015c716368> 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 0x0000000143b80d20> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000143b80d20> 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 0x0000000143bbfde0> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000143bbfde0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000143bbfde0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000143bbfde0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014df9e9a0> 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 0x00000001466f8950> 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 0x107bcd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107bcd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107bd17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014e7743a0>, <W_TypeObject 'GenericAlias' at 0x146c57ef8>, ...] 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 0x15cbf7c20> 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 0x15cbf7c20> 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 0x15cbf7c20> 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 0x15cbf7c20> 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 0x107c5e4a0>> w_obj = <W_TypeObject 'ellipsis' at 0x15cbf7c20> 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 0x15cbf7c20>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107c5e4a0>> 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 0x15cbf7c20> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107c5e4a0>> @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 0x107c5e4a0>> 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 0x107c5e4a0>> 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 0x000000014c1e9790>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x00000001451121d8> 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 0x000000014de4f0e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014de4f0e0> 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 0x0000000124855718> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000124855718> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000124855718> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000124855718> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000147968560> 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 0x000000015df26f00> 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 0x10494d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10494d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1049517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000124855c90>, <W_TypeObject 'GenericAlias' at 0x14b69ac60>, ...] 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 0x14b6d61e0> 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 0x14b6d61e0> 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 0x14b6d61e0> 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 0x14b6d61e0> 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 0x1071f02a0>> w_obj = <W_TypeObject 'ellipsis' at 0x14b6d61e0> 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 0x14b6d61e0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1071f02a0>> 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 0x14b6d61e0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1071f02a0>> @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 0x1071f02a0>> 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 0x1071f02a0>> 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 0x0000000110b80278>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014b890ac0> 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 0x0000000126555ce0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000126555ce0> 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 0x0000000131312790> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000131312790> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000131312790> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000131312790> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000013126f960> 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 0x00000001261491a0> 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 0x106d85680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x106d85660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x106d897b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000131312d08>, <W_TypeObject 'GenericAlias' at 0x15b902170>, ...] 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 0x15c269ec0> 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 0x15c269ec0> 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 0x15c269ec0> 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 0x15c269ec0> 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 0x1074f2fd0>> w_obj = <W_TypeObject 'ellipsis' at 0x15c269ec0> 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 0x15c269ec0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1074f2fd0>> 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 0x15c269ec0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1074f2fd0>> @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 0x1074f2fd0>> 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 0x1074f2fd0>> 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 0x00000001453e6bd8>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014d17f600> 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 0x00000001461d0860> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001461d0860> 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 0x000000015da87590> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015da87590> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015da87590> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000015da87590> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001461d1f60> 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 0x00000001110a3558> 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 0x10794d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10794d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000015da87b08>, <W_TypeObject 'GenericAlias' at 0x14c88d6e0>, ...] 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 0x1436031a0> 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 0x1436031a0> 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 0x1436031a0> 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 0x1436031a0> 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 0x1077f7460>> w_obj = <W_TypeObject 'ellipsis' at 0x1436031a0> 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 0x1436031a0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1077f7460>> 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 0x1436031a0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1077f7460>> @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 0x1077f7460>> 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 0x1077f7460>> 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 0x0000000146cce6b0>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x00000001454e6520> 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 0x0000000160654f20> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000160654f20> 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 0x000000015d737520> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015d737520> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015d737520> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000015d737520> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015c95c760> 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 0x0000000145653ec0> 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 0x1079cd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1079cd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079d17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000015d737a98>, <W_TypeObject 'GenericAlias' at 0x144453788>, ...] 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 0x1472c1910> 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 0x1472c1910> 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 0x1472c1910> 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 0x1472c1910> 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 0x1078d2ef0>> w_obj = <W_TypeObject 'ellipsis' at 0x1472c1910> 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 0x1472c1910>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1078d2ef0>> 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 0x1472c1910> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1078d2ef0>> @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 0x1078d2ef0>> 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 0x1078d2ef0>> 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 0x0000000144563010>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000144737740> 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 0x00000001443ad8a0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001443ad8a0> 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 0x000000014e46e330> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014e46e330> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014e46e330> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014e46e330> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000012581b1e0> 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 0x00000001456ce758> 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 0x107b4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107b4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107b517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014e46e8a8>, <W_TypeObject 'GenericAlias' at 0x146f4f980>, ...] 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 0x15d14fb08> 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 0x15d14fb08> 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 0x15d14fb08> 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 0x15d14fb08> 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 0x1078bc810>> w_obj = <W_TypeObject 'ellipsis' at 0x15d14fb08> 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 0x15d14fb08>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1078bc810>> 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 0x15d14fb08> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1078bc810>> @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 0x1078bc810>> 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 0x1078bc810>> 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 0x00000001448b7718>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x00000001458148b8> 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 0x000000014519d5e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014519d5e0> 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 0x0000000123cb6a68> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000123cb6a68> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000123cb6a68> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000123cb6a68> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000126fd5460> 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 0x000000015d878de8> 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 0x107d4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107d4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107d517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000123cb7408>, <W_TypeObject 'GenericAlias' at 0x110e061a8>, ...] 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 0x15cce3d70> 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 0x15cce3d70> 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 0x15cce3d70> 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 0x15cce3d70> 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 0x11d6b1500>> w_obj = <W_TypeObject 'ellipsis' at 0x15cce3d70> 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 0x15cce3d70>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11d6b1500>> 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 0x15cce3d70> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11d6b1500>> @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 0x11d6b1500>> 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 0x11d6b1500>> 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 0x00000001501aadb8>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x00000001254092e0> 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 0x0000000124ea0c60> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000124ea0c60> 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 0x0000000124ea3440> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000124ea3440> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000124ea3440> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000124ea3440> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000146308220> 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 0x0000000111076c28> 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 0x10494d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10494d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1049517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000124ea39b8>, <W_TypeObject 'GenericAlias' at 0x15b291ad0>, ...] 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 0x15b2e26b0> 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 0x15b2e26b0> 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 0x15b2e26b0> 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 0x15b2e26b0> 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 0x1070f6450>> w_obj = <W_TypeObject 'ellipsis' at 0x15b2e26b0> 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 0x15b2e26b0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1070f6450>> 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 0x15b2e26b0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1070f6450>> @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 0x1070f6450>> 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 0x1070f6450>> 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 0x000000015ba1be20>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014b891290> 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 0x000000015d6a04a0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015d6a04a0> 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 0x000000015d906d08> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015d906d08> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015d906d08> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000015d906d08> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015d6a1ca0> 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 0x0000000130df62f8> 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 0x106d85680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x106d85660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x106d897b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000015d907520>, <W_TypeObject 'GenericAlias' at 0x14ed0e7c8>, ...] 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 0x14e8bc800> 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 0x14e8bc800> 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 0x14e8bc800> 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 0x14e8bc800> 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 0x1073c3080>> w_obj = <W_TypeObject 'ellipsis' at 0x14e8bc800> 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 0x14e8bc800>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1073c3080>> 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 0x14e8bc800> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1073c3080>> @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 0x1073c3080>> 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 0x1073c3080>> 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 0x00000001453e6368>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014d17e610> 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 0x000000015c097820> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015c097820> 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 0x000000014c238170> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014c238170> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014c238170> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014c238170> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014e7793a0> 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 0x0000000130d55280> 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 0x10794d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10794d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014c238c28>, <W_TypeObject 'GenericAlias' at 0x14d24afa8>, ...] 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 0x14d2729c0> 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 0x14d2729c0> 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 0x14d2729c0> 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 0x14d2729c0> 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 0x10750a780>> w_obj = <W_TypeObject 'ellipsis' at 0x14d2729c0> 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 0x14d2729c0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10750a780>> 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 0x14d2729c0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10750a780>> @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 0x10750a780>> 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 0x10750a780>> 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 0x000000014f2e2728>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014d578b10> 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 0x0000000126822420> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000126822420> 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 0x000000015ca28c28> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015ca28c28> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015ca28c28> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000015ca28c28> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000126823ce0> 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 0x000000014e3c1b40> 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 0x1079cd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1079cd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079d17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000015ca291a0>, <W_TypeObject 'GenericAlias' at 0x14d81e100>, ...] 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 0x14d7e1600> 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 0x14d7e1600> 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 0x14d7e1600> 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 0x14d7e1600> 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 0x1077178e0>> w_obj = <W_TypeObject 'ellipsis' at 0x14d7e1600> 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 0x14d7e1600>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1077178e0>> 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 0x14d7e1600> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1077178e0>> @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 0x1077178e0>> 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 0x1077178e0>> 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 0x0000000110d62f98>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014f2406b0> 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 0x0000000144479b60> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000144479b60> 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 0x000000016061a800> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000016061a800> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000016061a800> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000016061a800> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000147201420> 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 0x000000014e0dc100> 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 0x107b4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107b4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107b517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000016061ad78>, <W_TypeObject 'GenericAlias' at 0x14ea61868>, ...] 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 0x110ccb718> 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 0x110ccb718> 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 0x110ccb718> 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 0x110ccb718> 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 0x1075befa0>> w_obj = <W_TypeObject 'ellipsis' at 0x110ccb718> 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 0x110ccb718>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1075befa0>> 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 0x110ccb718> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1075befa0>> @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 0x1075befa0>> 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 0x1075befa0>> 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 0x000000014489b808>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000144b125c0> 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 0x00000001272748a0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001272748a0> 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 0x000000012728e138> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000012728e138> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000012728e138> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000012728e138> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000125a34120> 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 0x0000000125a6cb48> 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 0x107bcd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107bcd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107bd17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000012728e6b0>, <W_TypeObject 'GenericAlias' at 0x14ec69b40>, ...] 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 0x13143cc60> 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 0x13143cc60> 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 0x13143cc60> 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 0x13143cc60> 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 0x107eb13b0>> w_obj = <W_TypeObject 'ellipsis' at 0x13143cc60> 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 0x13143cc60>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107eb13b0>> 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 0x13143cc60> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107eb13b0>> @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 0x107eb13b0>> 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 0x107eb13b0>> 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 0x0000000145c56cc8>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000147612d40> 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 0x000000014624a3e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014624a3e0> 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 0x000000014629dda8> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014629dda8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014629dda8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014629dda8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014624bae0> 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 0x00000001279dbe88> 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 0x10494d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10494d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1049517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014f274368>, <W_TypeObject 'GenericAlias' at 0x15b290f00>, ...] 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 0x15b2dd670> 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 0x15b2dd670> 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 0x15b2dd670> 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 0x15b2dd670> 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 0x1074dd9d0>> w_obj = <W_TypeObject 'ellipsis' at 0x15b2dd670> 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 0x15b2dd670>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1074dd9d0>> 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 0x15b2dd670> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1074dd9d0>> @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 0x1074dd9d0>> 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 0x1074dd9d0>> 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 0x000000015ba1bc40>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014372bba0> 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 0x000000015dd538e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015dd538e0> 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 0x000000014cddf6a8> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014cddf6a8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014cddf6a8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014cddf6a8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015b2133a0> 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 0x00000001277c0f70> 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 0x106d85680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x106d85660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x106d897b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014cddfc20>, <W_TypeObject 'GenericAlias' at 0x1268609f8>, ...] 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 0x14e9bd2b8> 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 0x14e9bd2b8> 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 0x14e9bd2b8> 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 0x14e9bd2b8> 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 0x1073f8920>> w_obj = <W_TypeObject 'ellipsis' at 0x14e9bd2b8> 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 0x14e9bd2b8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1073f8920>> 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 0x14e9bd2b8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1073f8920>> @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 0x1073f8920>> 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 0x1073f8920>> 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 0x00000001453e6d40>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000111237380> 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 0x00000001455b83a0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001455b83a0> 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 0x000000014ec82d40> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014ec82d40> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014ec82d40> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014ec82d40> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001455b9a60> 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 0x000000015cf9e058> 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 0x10794d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10794d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014ec833d0>, <W_TypeObject 'GenericAlias' at 0x12590f440>, ...] 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 0x1258c54b0> 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 0x1258c54b0> 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 0x1258c54b0> 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 0x1258c54b0> 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 0x1075cbdd0>> w_obj = <W_TypeObject 'ellipsis' at 0x1258c54b0> 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 0x1258c54b0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1075cbdd0>> 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 0x1258c54b0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1075cbdd0>> @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 0x1075cbdd0>> 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 0x1075cbdd0>> 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 0x000000014e81df88>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000015c3efe48> 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 0x0000000124291ea0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000124291ea0> 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 0x0000000124ad08e0> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000124ad08e0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000124ad08e0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000124ad08e0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015bd33860> 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 0x000000012746c0c8> 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 0x1079cd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1079cd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079d17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000124ad0e58>, <W_TypeObject 'GenericAlias' at 0x15d4d7be8>, ...] 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 0x146d4f910> 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 0x146d4f910> 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 0x146d4f910> 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 0x146d4f910> 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 0x1077dfc90>> w_obj = <W_TypeObject 'ellipsis' at 0x146d4f910> 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 0x146d4f910>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1077dfc90>> 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 0x146d4f910> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1077dfc90>> @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 0x1077dfc90>> 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 0x1077dfc90>> 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 0x0000000110dc1f88>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x00000001315897b8> 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 0x000000015c01d7e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015c01d7e0> 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 0x000000014eb28250> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014eb28250> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014eb28250> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014eb28250> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014e5b1120> 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 0x000000015bd92218> 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 0x107b4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107b4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107b517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014eb287c8>, <W_TypeObject 'GenericAlias' at 0x14cc157f8>, ...] 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 0x14cc2ec98> 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 0x14cc2ec98> 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 0x14cc2ec98> 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 0x14cc2ec98> 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 0x107cd9040>> w_obj = <W_TypeObject 'ellipsis' at 0x14cc2ec98> 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 0x14cc2ec98>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107cd9040>> 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 0x14cc2ec98> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107cd9040>> @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 0x107cd9040>> 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 0x107cd9040>> 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 0x00000001110995b0>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014db862c8> 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 0x000000015cef9620> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015cef9620> 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 0x000000015d04b6e0> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015d04b6e0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015d04b6e0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000015d04b6e0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000126a26ea0> 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 0x0000000145f7ff68> 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 0x107d4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107d4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107d517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000015d04bc58>, <W_TypeObject 'GenericAlias' at 0x1464f8598>, ...] 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 0x1464d3e50> 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 0x1464d3e50> 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 0x1464d3e50> 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 0x1464d3e50> 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 0x107f9ee30>> w_obj = <W_TypeObject 'ellipsis' at 0x1464d3e50> 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 0x1464d3e50>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107f9ee30>> 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 0x1464d3e50> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107f9ee30>> @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 0x107f9ee30>> 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 0x107f9ee30>> 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 0x0000000145be8020>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000146341e98> 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 0x00000001253f75a0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001253f75a0> 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 0x0000000125448288> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000125448288> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000125448288> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000125448288> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001312136e0> 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 0x000000014e71a0c8> 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 0x10494d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10494d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1049517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000125448800>, <W_TypeObject 'GenericAlias' at 0x15b25f8a0>, ...] 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 0x15b2a2e20> 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 0x15b2a2e20> 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 0x15b2a2e20> 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 0x15b2a2e20> 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 0x1074dff90>> w_obj = <W_TypeObject 'ellipsis' at 0x15b2a2e20> 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 0x15b2a2e20>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1074dff90>> 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 0x15b2a2e20> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1074dff90>> @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 0x1074dff90>> 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 0x1074dff90>> 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 0x000000015ba3b970>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x00000001436e2b60> 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 0x00000001438078a0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001438078a0> 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 0x000000014ce5d6e0> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014ce5d6e0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014ce5d6e0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014ce5d6e0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000143801260> 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 0x000000015ca12608> 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 0x106d85680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x106d85660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x106d897b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014ce5dc58>, <W_TypeObject 'GenericAlias' at 0x15da3fa60>, ...] 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 0x14c661de0> 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 0x14c661de0> 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 0x14c661de0> 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 0x14c661de0> 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 0x107598740>> w_obj = <W_TypeObject 'ellipsis' at 0x14c661de0> 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 0x14c661de0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107598740>> 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 0x14c661de0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107598740>> @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 0x107598740>> 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 0x107598740>> 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 0x000000014548b4c0>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000111236d90> 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 0x000000014e0bfe20> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014e0bfe20> 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 0x000000012758ce90> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000012758ce90> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000012758ce90> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000012758ce90> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014e0d3be0> 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 0x0000000126e2f718> 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 0x10794d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10794d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000012758d478>, <W_TypeObject 'GenericAlias' at 0x1436024b8>, ...] 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 0x14cbdde88> 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 0x14cbdde88> 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 0x14cbdde88> 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 0x14cbdde88> 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 0x1077ed5f0>> w_obj = <W_TypeObject 'ellipsis' at 0x14cbdde88> 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 0x14cbdde88>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1077ed5f0>> 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 0x14cbdde88> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1077ed5f0>> @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 0x1077ed5f0>> 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 0x1077ed5f0>> 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 0x0000000125365d30>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x00000001454e7268> 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 0x000000015d1388e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015d1388e0> 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 0x00000001266ca250> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001266ca250> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001266ca250> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x00000001266ca250> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001468662a0> 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 0x0000000145e6e100> 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 0x1079cd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1079cd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079d17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x00000001266ca7c8>, <W_TypeObject 'GenericAlias' at 0x124c06988>, ...] 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 0x124c4a100> 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 0x124c4a100> 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 0x124c4a100> 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 0x124c4a100> 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 0x107c91e00>> w_obj = <W_TypeObject 'ellipsis' at 0x124c4a100> 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 0x124c4a100>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107c91e00>> 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 0x124c4a100> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107c91e00>> @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 0x107c91e00>> 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 0x107c91e00>> 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 0x0000000150194d40>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014cfb5b78> 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 0x0000000126a80020> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000126a80020> 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 0x00000001471f6330> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001471f6330> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001471f6330> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x00000001471f6330> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000126a81ae0> 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 0x00000001262672f0> 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 0x107b4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107b4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107b517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x00000001471f68a8>, <W_TypeObject 'GenericAlias' at 0x125181670>, ...] 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 0x1251d74b0> 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 0x1251d74b0> 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 0x1251d74b0> 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 0x1251d74b0> 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 0x1076d3140>> w_obj = <W_TypeObject 'ellipsis' at 0x1251d74b0> 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 0x1251d74b0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1076d3140>> 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 0x1251d74b0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1076d3140>> @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 0x1076d3140>> 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 0x1076d3140>> 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 0x0000000146c5aae8>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014e174a98> 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 0x000000014da4a320> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014da4a320> 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 0x00000001276ee528> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001276ee528> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001276ee528> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x00000001276ee528> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014da4bd20> 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 0x0000000146c2aec8> 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 0x107bcd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107bcd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107bd17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x00000001276eeaa0>, <W_TypeObject 'GenericAlias' at 0x14cd81408>, ...] 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 0x146fb85d0> 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 0x146fb85d0> 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 0x146fb85d0> 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 0x146fb85d0> 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 0x107c22d20>> w_obj = <W_TypeObject 'ellipsis' at 0x146fb85d0> 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 0x146fb85d0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107c22d20>> 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 0x146fb85d0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107c22d20>> @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 0x107c22d20>> 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 0x107c22d20>> 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 0x000000014ca7fcb8>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014ed98890> 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 0x000000014f144760> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014f144760> 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 0x000000014f1b2170> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014f1b2170> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014f1b2170> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014f1b2170> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014f145be0> 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 0x000000014729a368> 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 0x10494d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10494d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1049517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014f1b26e8>, <W_TypeObject 'GenericAlias' at 0x15b1ef670>, ...] 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 0x15b255ec0> 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 0x15b255ec0> 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 0x15b255ec0> 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 0x15b255ec0> 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 0x1070f8660>> w_obj = <W_TypeObject 'ellipsis' at 0x15b255ec0> 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 0x15b255ec0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1070f8660>> 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 0x15b255ec0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1070f8660>> @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 0x1070f8660>> 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 0x1070f8660>> 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 0x000000015b988020>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x00000001436b18f8> 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 0x000000015be9c420> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015be9c420> 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 0x00000001444dd718> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001444dd718> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001444dd718> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x00000001444dd718> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015be9dc20> 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 0x00000001252adf68> 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 0x106d85680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x106d85660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x106d897b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x00000001444ddda8>, <W_TypeObject 'GenericAlias' at 0x15cf0a790>, ...] 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 0x15cd07910> 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 0x15cd07910> 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 0x15cd07910> 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 0x15cd07910> 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 0x107624ce0>> w_obj = <W_TypeObject 'ellipsis' at 0x15cd07910> 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 0x15cd07910>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107624ce0>> 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 0x15cd07910> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107624ce0>> @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 0x107624ce0>> 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 0x107624ce0>> 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 0x000000014540a188>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014d6d09f8> 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 0x0000000127565f20> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000127565f20> 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 0x0000000124266368> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000124266368> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000124266368> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000124266368> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014e7789a0> 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 0x0000000124ad1280> 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 0x10794d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10794d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x00000001242668e0>, <W_TypeObject 'GenericAlias' at 0x160a8cd08>, ...] 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 0x110bdae58> 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 0x110bdae58> 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 0x110bdae58> 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 0x110bdae58> 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 0x1077e7e80>> w_obj = <W_TypeObject 'ellipsis' at 0x110bdae58> 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 0x110bdae58>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1077e7e80>> 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 0x110bdae58> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1077e7e80>> @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 0x1077e7e80>> 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 0x1077e7e80>> 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 0x0000000146ae4368>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000012753c660> 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 0x000000015e98dba0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015e98dba0> 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 0x000000014388c218> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014388c218> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014388c218> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014388c218> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001449774a0> 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 0x0000000146746c28> 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 0x1079cd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1079cd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079d17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014388c790>, <W_TypeObject 'GenericAlias' at 0x125939750>, ...] 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 0x12593a950> 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 0x12593a950> 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 0x12593a950> 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 0x12593a950> 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 0x10765d9c0>> w_obj = <W_TypeObject 'ellipsis' at 0x12593a950> 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 0x12593a950>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10765d9c0>> 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 0x12593a950> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10765d9c0>> @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 0x10765d9c0>> 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 0x10765d9c0>> 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 0x00000001459ffda8>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014603dee8> 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 0x0000000127a8faa0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000127a8faa0> 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 0x0000000123cba0c8> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000123cba0c8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000123cba0c8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000123cba0c8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014c64efa0> 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 0x000000014eb0e800> 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 0x107b4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107b4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107b517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000123cba640>, <W_TypeObject 'GenericAlias' at 0x14c75c058>, ...] 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 0x143b732f0> 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 0x143b732f0> 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 0x143b732f0> 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 0x143b732f0> 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 0x107c10f80>> w_obj = <W_TypeObject 'ellipsis' at 0x143b732f0> 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 0x143b732f0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107c10f80>> 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 0x143b732f0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107c10f80>> @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 0x107c10f80>> 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 0x107c10f80>> 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 0x000000015d8c3880>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000015bf04228> 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 0x000000015c0a6720> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015c0a6720> 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 0x0000000144d83130> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000144d83130> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000144d83130> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000144d83130> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014c628060> 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 0x000000014c67e950> 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 0x107d4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107d4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107d517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000144d836a8>, <W_TypeObject 'GenericAlias' at 0x14e596c98>, ...] 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 0x15e32e020> 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 0x15e32e020> 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 0x15e32e020> 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 0x15e32e020> 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 0x10d769b10>> w_obj = <W_TypeObject 'ellipsis' at 0x15e32e020> 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 0x15e32e020>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10d769b10>> 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 0x15e32e020> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10d769b10>> @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 0x10d769b10>> 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 0x10d769b10>> 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 0x000000015cd5d628>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x00000001262a7358> 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 0x000000015c7b3de0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015c7b3de0> 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 0x000000015c786368> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015c786368> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015c786368> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000015c786368> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000125bf3560> 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 0x000000014729a6e8> 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 0x10494d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10494d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1049517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000015c7868e0>, <W_TypeObject 'GenericAlias' at 0x15b1a92f0>, ...] 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 0x15b24ce20> 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 0x15b24ce20> 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 0x15b24ce20> 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 0x15b24ce20> 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 0x1071c5a00>> w_obj = <W_TypeObject 'ellipsis' at 0x15b24ce20> 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 0x15b24ce20>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1071c5a00>> 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 0x15b24ce20> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1071c5a00>> @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 0x1071c5a00>> 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 0x1071c5a00>> 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 0x000000015ba3a548>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000123b4ae58> 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 0x000000015d67bce0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015d67bce0> 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 0x000000015df8cf38> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015df8cf38> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015df8cf38> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000015df8cf38> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015d6a16e0> 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 0x000000014c7b31d8> 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 0x106d85680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x106d85660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x106d897b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000015df8d4b0>, <W_TypeObject 'GenericAlias' at 0x145224a68>, ...] 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 0x126e8ce20> 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 0x126e8ce20> 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 0x126e8ce20> 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 0x126e8ce20> 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 0x107777020>> w_obj = <W_TypeObject 'ellipsis' at 0x126e8ce20> 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 0x126e8ce20>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107777020>> 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 0x126e8ce20> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107777020>> @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 0x107777020>> 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 0x107777020>> 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 0x000000014d73d088>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000111237998> 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 0x000000014e12ece0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014e12ece0> 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 0x0000000110aafe50> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000110aafe50> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000110aafe50> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000110aafe50> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014d588ce0> 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 0x000000014e198bb8> 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 0x10794d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10794d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000125968410>, <W_TypeObject 'GenericAlias' at 0x14510dbe8>, ...] 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 0x12593a6e8> 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 0x12593a6e8> 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 0x12593a6e8> 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 0x12593a6e8> 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 0x1076cd2e0>> w_obj = <W_TypeObject 'ellipsis' at 0x12593a6e8> 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 0x12593a6e8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1076cd2e0>> 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 0x12593a6e8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1076cd2e0>> @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 0x1076cd2e0>> 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 0x1076cd2e0>> 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 0x0000000145838548>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000015dc47240> 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 0x000000015ca14960> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015ca14960> 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 0x00000001456831a0> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001456831a0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001456831a0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x00000001456831a0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001606541a0> 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 0x0000000125f669f8> 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 0x1079cd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1079cd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079d17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000145683718>, <W_TypeObject 'GenericAlias' at 0x15b5da368>, ...] 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 0x14c8da448> 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 0x14c8da448> 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 0x14c8da448> 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 0x14c8da448> 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 0x1076875d0>> w_obj = <W_TypeObject 'ellipsis' at 0x14c8da448> 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 0x14c8da448>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1076875d0>> 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 0x14c8da448> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1076875d0>> @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 0x1076875d0>> 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 0x1076875d0>> 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 0x00000001448b31f0>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014657f8d0> 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 0x000000014f1e0ce0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014f1e0ce0> 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 0x0000000145b97980> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000145b97980> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000145b97980> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000145b97980> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015c01c920> 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 0x0000000123c4d4e8> 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 0x107b4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107b4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107b517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000145b97ef8>, <W_TypeObject 'GenericAlias' at 0x1257301e0>, ...] 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 0x12575e250> 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 0x12575e250> 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 0x12575e250> 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 0x12575e250> 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 0x107cfae60>> w_obj = <W_TypeObject 'ellipsis' at 0x12575e250> 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 0x12575e250>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107cfae60>> 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 0x12575e250> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107cfae60>> @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 0x107cfae60>> 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 0x107cfae60>> 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 0x000000015cda24d0>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000144603128> 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 0x000000014da69560> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014da69560> 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 0x000000014da6f0c0> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014da6f0c0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014da6f0c0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014da6f0c0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014d41f560> 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 0x000000014db37a98> 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 0x107bcd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107bcd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107bd17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014616a678>, <W_TypeObject 'GenericAlias' at 0x15019ead8>, ...] 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 0x1501c3c90> 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 0x1501c3c90> 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 0x1501c3c90> 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 0x1501c3c90> 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 0x10774c930>> w_obj = <W_TypeObject 'ellipsis' at 0x1501c3c90> 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 0x1501c3c90>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10774c930>> 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 0x1501c3c90> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10774c930>> @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 0x10774c930>> 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 0x10774c930>> 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 0x000000014483d628>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000145ae0250> 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 0x00000001111dbde0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001111dbde0> 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 0x0000000145adc090> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000145adc090> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000145adc090> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000145adc090> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000145b09260> 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 0x0000000125092560> 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 0x10494d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10494d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1049517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000145adc608>, <W_TypeObject 'GenericAlias' at 0x143596950>, ...] 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 0x15b23f4b0> 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 0x15b23f4b0> 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 0x15b23f4b0> 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 0x15b23f4b0> 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 0x107532340>> w_obj = <W_TypeObject 'ellipsis' at 0x15b23f4b0> 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 0x15b23f4b0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107532340>> 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 0x15b23f4b0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107532340>> @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 0x107532340>> 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 0x107532340>> 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 0x000000015b9ecf98>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000123b16ac0> 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 0x000000015b212260> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015b212260> 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 0x0000000144968b10> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000144968b10> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000144968b10> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000144968b10> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015b213fa0> 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 0x0000000110f80bb8> 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 0x106d85680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x106d85660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x106d897b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000144969088>, <W_TypeObject 'GenericAlias' at 0x1476bc1a8>, ...] 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 0x143b24560> 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 0x143b24560> 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 0x143b24560> 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 0x143b24560> 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 0x1076f8330>> w_obj = <W_TypeObject 'ellipsis' at 0x143b24560> 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 0x143b24560>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1076f8330>> 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 0x143b24560> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1076f8330>> @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 0x1076f8330>> 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 0x1076f8330>> 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 0x000000014d73dad8>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014d6d01b0> 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 0x000000015c4138a0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015c4138a0> 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 0x000000014cdf30c0> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014cdf30c0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014cdf30c0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014cdf30c0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015dc5f1a0> 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 0x0000000144ef6288> 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 0x10794d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10794d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014cdf36a8>, <W_TypeObject 'GenericAlias' at 0x15c4e9638>, ...] 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 0x1112f3130> 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 0x1112f3130> 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 0x1112f3130> 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 0x1112f3130> 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 0x10759be80>> w_obj = <W_TypeObject 'ellipsis' at 0x1112f3130> 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 0x1112f3130>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10759be80>> 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 0x1112f3130> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10759be80>> @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 0x10759be80>> 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 0x10759be80>> 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 0x00000001454fdb50>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000145b87a38> 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 0x000000015e924920> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015e924920> 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 0x000000014d029980> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014d029980> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014d029980> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014d029980> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015e98c160> 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 0x00000001249fa2f8> 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 0x1079cd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1079cd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079d17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014d029ef8>, <W_TypeObject 'GenericAlias' at 0x125a7e988>, ...] 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 0x1113fc170> 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 0x1113fc170> 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 0x1113fc170> 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 0x1113fc170> 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 0x1072345e0>> w_obj = <W_TypeObject 'ellipsis' at 0x1113fc170> 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 0x1113fc170>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1072345e0>> 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 0x1113fc170> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1072345e0>> @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 0x1072345e0>> 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 0x1072345e0>> 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 0x000000014489ab60>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000125c54f48> 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 0x000000015d9d58e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015d9d58e0> 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 0x000000014e21a448> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014e21a448> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014e21a448> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014e21a448> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014c927360> 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 0x000000015c4989f8> 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 0x107b4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107b4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107b517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014e21a9c0>, <W_TypeObject 'GenericAlias' at 0x1464f9478>, ...] 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 0x1464d74b0> 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 0x1464d74b0> 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 0x1464d74b0> 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 0x1464d74b0> 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 0x10767cab0>> w_obj = <W_TypeObject 'ellipsis' at 0x1464d74b0> 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 0x1464d74b0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10767cab0>> 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 0x1464d74b0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10767cab0>> @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 0x10767cab0>> 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 0x10767cab0>> 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 0x000000014e6ea020>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000110e0c480> 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 0x000000014d219120> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014d219120> 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 0x0000000126e06480> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000126e06480> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000126e06480> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000126e06480> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015c236220> 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 0x00000001608b08a8> 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 0x107d4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107d4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107d517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000126e06de8>, <W_TypeObject 'GenericAlias' at 0x145cd7ad0>, ...] 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 0x1447658a0> 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 0x1447658a0> 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 0x1447658a0> 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 0x1447658a0> 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 0x107f39c50>> w_obj = <W_TypeObject 'ellipsis' at 0x1447658a0> 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 0x1447658a0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107f39c50>> 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 0x1447658a0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107f39c50>> @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 0x107f39c50>> 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 0x107f39c50>> 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 0x00000001457e5628>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000126284c78> 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 0x00000001463667e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001463667e0> 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 0x0000000146344410> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000146344410> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000146344410> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000146344410> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000146367e20> 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 0x0000000145268db0> 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 0x10494d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10494d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1049517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000146344988>, <W_TypeObject 'GenericAlias' at 0x143550090>, ...] 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 0x15b1eede8> 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 0x15b1eede8> 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 0x15b1eede8> 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 0x15b1eede8> 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 0x10738ed60>> w_obj = <W_TypeObject 'ellipsis' at 0x15b1eede8> 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 0x15b1eede8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10738ed60>> 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 0x15b1eede8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10738ed60>> @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 0x10738ed60>> 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 0x10738ed60>> 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 0x000000015b989088>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000123b16a20> 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 0x0000000123e97da0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000123e97da0> 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 0x000000014cead638> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014cead638> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014cead638> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014cead638> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015b8735a0> 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 0x00000001450f58d8> 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 0x106d85680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x106d85660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x106d897b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014ceadbb0>, <W_TypeObject 'GenericAlias' at 0x14673ecd0>, ...] 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 0x14f449328> 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 0x14f449328> 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 0x14f449328> 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 0x14f449328> 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 0x10764f6d0>> w_obj = <W_TypeObject 'ellipsis' at 0x14f449328> 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 0x14f449328>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10764f6d0>> 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 0x14f449328> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10764f6d0>> @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 0x10764f6d0>> 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 0x10764f6d0>> 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 0x000000014d798890>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000015e115128> 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 0x000000014e0d27a0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014e0d27a0> 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 0x0000000126d6d5c8> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000126d6d5c8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000126d6d5c8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000126d6d5c8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014e12e260> 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 0x000000015e571c90> 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 0x10794d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10794d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000126d6db40>, <W_TypeObject 'GenericAlias' at 0x14e060090>, ...] 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 0x127a61130> 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 0x127a61130> 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 0x127a61130> 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 0x127a61130> 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 0x10786ded0>> w_obj = <W_TypeObject 'ellipsis' at 0x127a61130> 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 0x127a61130>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10786ded0>> 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 0x127a61130> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10786ded0>> @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 0x10786ded0>> 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 0x10786ded0>> 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 0x0000000126ae5b50>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000015c3ee5c0> 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 0x000000012577dca0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000012577dca0> 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 0x00000001448518a0> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001448518a0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001448518a0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x00000001448518a0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000131571920> 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 0x0000000110fdbfa0> 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 0x1079cd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1079cd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079d17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000144851e18>, <W_TypeObject 'GenericAlias' at 0x145644640>, ...] 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 0x1265a4800> 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 0x1265a4800> 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 0x1265a4800> 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 0x1265a4800> 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 0x10788fdb0>> w_obj = <W_TypeObject 'ellipsis' at 0x1265a4800> 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 0x1265a4800>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10788fdb0>> 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 0x1265a4800> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10788fdb0>> @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 0x10788fdb0>> 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 0x10788fdb0>> 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 0x000000015c523bc8>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014f23d290> 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 0x000000014d4eda20> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014d4eda20> 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 0x0000000125fe90f8> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000125fe90f8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000125fe90f8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000125fe90f8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001462a38a0> 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 0x0000000145876678> 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 0x107b4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107b4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107b517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000125fe9670>, <W_TypeObject 'GenericAlias' at 0x1257de1e0>, ...] 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 0x1257f9e18> 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 0x1257f9e18> 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 0x1257f9e18> 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 0x1257f9e18> 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 0x107fc5ef0>> w_obj = <W_TypeObject 'ellipsis' at 0x1257f9e18> 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 0x1257f9e18>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107fc5ef0>> 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 0x1257f9e18> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107fc5ef0>> @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 0x107fc5ef0>> 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 0x107fc5ef0>> 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 0x000000014ca7e110>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014c262138> 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 0x000000011137fea0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000011137fea0> 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 0x0000000126aafb40> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000126aafb40> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000126aafb40> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000126aafb40> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014e4b1a20> 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 0x0000000126352ec8> 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 0x107bcd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107bcd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107bd17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014e450100>, <W_TypeObject 'GenericAlias' at 0x14c4c21e0>, ...] 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 0x14c509ef8> 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 0x14c509ef8> 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 0x14c509ef8> 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 0x14c509ef8> 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 0x107f86230>> w_obj = <W_TypeObject 'ellipsis' at 0x14c509ef8> 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 0x14c509ef8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107f86230>> 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 0x14c509ef8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107f86230>> @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 0x107f86230>> 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 0x107f86230>> 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 0x0000000131415f88>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000125fb1a88> 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 0x000000012608ad60> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000012608ad60> 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 0x0000000126097520> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000126097520> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000126097520> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000126097520> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000146366420> 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 0x0000000145269750> 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 0x10494d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10494d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1049517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000126097a98>, <W_TypeObject 'GenericAlias' at 0x14356f398>, ...] 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 0x15b1f9980> 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 0x15b1f9980> 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 0x15b1f9980> 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 0x15b1f9980> 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 0x1075b3020>> w_obj = <W_TypeObject 'ellipsis' at 0x15b1f9980> 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 0x15b1f9980>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1075b3020>> 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 0x15b1f9980> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1075b3020>> @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 0x1075b3020>> 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 0x1075b3020>> 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 0x000000015b988728>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000143687df8> 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 0x0000000111229e20> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000111229e20> 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 0x000000015bb404f0> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015bb404f0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015bb404f0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000015bb404f0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014d7c16e0> 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 0x00000001468902c0> 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 0x106d85680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x106d85660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x106d897b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000015bb40a68>, <W_TypeObject 'GenericAlias' at 0x15d3dcd08>, ...] 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 0x14cae40c8> 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 0x14cae40c8> 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 0x14cae40c8> 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 0x14cae40c8> 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 0x1073cb9a0>> w_obj = <W_TypeObject 'ellipsis' at 0x14cae40c8> 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 0x14cae40c8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1073cb9a0>> 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 0x14cae40c8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1073cb9a0>> @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 0x1073cb9a0>> 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 0x1073cb9a0>> 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 0x000000014d7e92e0>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x00000001312677e0> 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 0x00000001251f38e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001251f38e0> 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 0x000000012758d0f8> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000012758d0f8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000012758d0f8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000012758d0f8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014e0bf060> 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 0x000000015c2ee3a0> 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 0x10794d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10794d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000012758d670>, <W_TypeObject 'GenericAlias' at 0x15c16f670>, ...] 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 0x110d21830> 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 0x110d21830> 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 0x110d21830> 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 0x110d21830> 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 0x107fcf550>> w_obj = <W_TypeObject 'ellipsis' at 0x110d21830> 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 0x110d21830>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107fcf550>> 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 0x110d21830> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107fcf550>> @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 0x107fcf550>> 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 0x107fcf550>> 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 0x0000000144cde5c0>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000145701740> 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 0x0000000125762360> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000125762360> 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 0x0000000146ba9da8> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000146ba9da8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000146ba9da8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000146ba9da8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000012577c2a0> 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 0x00000001608cb948> 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 0x1079cd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1079cd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079d17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000146bb2368>, <W_TypeObject 'GenericAlias' at 0x144989f68>, ...] 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 0x14b543b08> 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 0x14b543b08> 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 0x14b543b08> 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 0x14b543b08> 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 0x107c83c20>> w_obj = <W_TypeObject 'ellipsis' at 0x14b543b08> 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 0x14b543b08>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107c83c20>> 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 0x14b543b08> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107c83c20>> @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 0x107c83c20>> 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 0x107c83c20>> 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 0x0000000145ff8cc8>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000013153f150> 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 0x0000000143b83a60> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000143b83a60> 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 0x000000015e1e5d70> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015e1e5d70> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015e1e5d70> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000015e1e5d70> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000143b8d4e0> 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 0x0000000130e84790> 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 0x107b4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107b4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107b517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000124986448>, <W_TypeObject 'GenericAlias' at 0x1457466e8>, ...] 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 0x15d5aa218> 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 0x15d5aa218> 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 0x15d5aa218> 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 0x15d5aa218> 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 0x1078e2710>> w_obj = <W_TypeObject 'ellipsis' at 0x15d5aa218> 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 0x15d5aa218>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1078e2710>> 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 0x15d5aa218> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1078e2710>> @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 0x1078e2710>> 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 0x1078e2710>> 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 0x000000014dbbe890>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014d902a20> 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 0x000000014e4b1060> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014e4b1060> 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 0x000000014c940918> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014c940918> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014c940918> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014c940918> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001262ef420> 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 0x0000000126515440> 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 0x107d4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107d4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107d517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014c940e90>, <W_TypeObject 'GenericAlias' at 0x14e7e0d40>, ...] 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 0x14e7c9e18> 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 0x14e7c9e18> 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 0x14e7c9e18> 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 0x14e7c9e18> 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 0x107ee1440>> w_obj = <W_TypeObject 'ellipsis' at 0x14e7c9e18> 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 0x14e7c9e18>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107ee1440>> 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 0x14e7c9e18> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107ee1440>> @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 0x107ee1440>> 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 0x107ee1440>> 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 0x00000001271742f0>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000124ec1df8> 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 0x0000000126b0faa0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000126b0faa0> 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 0x0000000126af12b8> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000126af12b8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000126af12b8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000126af12b8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000012608b2a0> 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 0x0000000124ab3b78> 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 0x10494d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10494d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1049517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000126af1830>, <W_TypeObject 'GenericAlias' at 0x14b66e330>, ...] 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 0x1435c74b0> 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 0x1435c74b0> 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 0x1435c74b0> 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 0x1435c74b0> 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 0x10738a770>> w_obj = <W_TypeObject 'ellipsis' at 0x1435c74b0> 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 0x1435c74b0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10738a770>> 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 0x1435c74b0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10738a770>> @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 0x10738a770>> 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 0x10738a770>> 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 0x000000015ba1a368>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000123ade9d0> 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 0x000000014bb3e660> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014bb3e660> 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 0x000000014cead248> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014cead248> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014cead248> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014cead248> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014bb3fea0> 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 0x000000015ca13c90> 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 0x106d85680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x106d85660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x106d897b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014cead7f8>, <W_TypeObject 'GenericAlias' at 0x146792de8>, ...] 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 0x145927b78> 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 0x145927b78> 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 0x145927b78> 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 0x145927b78> 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 0x10762cf00>> w_obj = <W_TypeObject 'ellipsis' at 0x145927b78> 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 0x145927b78>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10762cf00>> 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 0x145927b78> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10762cf00>> @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 0x10762cf00>> 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 0x10762cf00>> 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 0x000000014da9e458>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000126646430> 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 0x00000001463a61e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001463a61e0> 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 0x000000015e3a90c0> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015e3a90c0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015e3a90c0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000015e3a90c0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001463a7ae0> 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 0x00000001464d2870> 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 0x10794d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10794d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000015e3a9638>, <W_TypeObject 'GenericAlias' at 0x12593a950>, ...] 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 0x124905328> 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 0x124905328> 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 0x124905328> 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 0x124905328> 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 0x107c75c60>> w_obj = <W_TypeObject 'ellipsis' at 0x124905328> 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 0x124905328>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107c75c60>> 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 0x124905328> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107c75c60>> @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 0x107c75c60>> 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 0x107c75c60>> 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 0x000000014e45a368>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x00000001454e74e8> 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 0x000000015bd32520> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015bd32520> 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 0x000000012751f5c8> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000012751f5c8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000012751f5c8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000012751f5c8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015bd33e20> 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 0x000000014e928480> 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 0x1079cd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1079cd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079d17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000012751fb40>, <W_TypeObject 'GenericAlias' at 0x13123a6e8>, ...] 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 0x15d8601e0> 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 0x15d8601e0> 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 0x15d8601e0> 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 0x15d8601e0> 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 0x107c8a090>> w_obj = <W_TypeObject 'ellipsis' at 0x15d8601e0> 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 0x15d8601e0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107c8a090>> 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 0x15d8601e0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107c8a090>> @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 0x107c8a090>> 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 0x107c8a090>> 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 0x000000015e3a5b50>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014f23c1b0> 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 0x000000015e3c36a0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015e3c36a0> 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 0x0000000125ce3750> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000125ce3750> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000125ce3750> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000125ce3750> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015c5833e0> 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 0x0000000131335e50> 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 0x107b4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107b4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107b517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000125ce3cc8>, <W_TypeObject 'GenericAlias' at 0x144ba6c98>, ...] 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 0x124448bb8> 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 0x124448bb8> 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 0x124448bb8> 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 0x124448bb8> 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 0x107ea26f0>> w_obj = <W_TypeObject 'ellipsis' at 0x124448bb8> 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 0x124448bb8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107ea26f0>> 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 0x124448bb8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107ea26f0>> @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 0x107ea26f0>> 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 0x107ea26f0>> 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 0x000000014e39d970>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000145bb84d0> 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 0x0000000124c8b3a0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000124c8b3a0> 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 0x000000014d3d8138> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014d3d8138> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014d3d8138> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014d3d8138> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000146e6ede0> 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 0x00000001470cd1d8> 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 0x107bcd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107bcd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107bd17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014d3d87c8>, <W_TypeObject 'GenericAlias' at 0x1271ee950>, ...] 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 0x1449da368> 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 0x1449da368> 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 0x1449da368> 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 0x1449da368> 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 0x107e486c0>> w_obj = <W_TypeObject 'ellipsis' at 0x1449da368> 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 0x1449da368>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107e486c0>> 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 0x1449da368> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107e486c0>> @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 0x107e486c0>> 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 0x107e486c0>> 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 0x000000015c9c6368>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000015dee54c0> 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 0x000000015e5a6160> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015e5a6160> 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 0x000000015e5dfa28> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015e5dfa28> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015e5dfa28> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000015e5dfa28> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015e5a74a0> 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 0x00000001462edfa0> 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 0x10494d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10494d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1049517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000015e5dffa0>, <W_TypeObject 'GenericAlias' at 0x143550de8>, ...] 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 0x15b1ef328> 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 0x15b1ef328> 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 0x15b1ef328> 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 0x15b1ef328> 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 0x1071b54e0>> w_obj = <W_TypeObject 'ellipsis' at 0x15b1ef328> 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 0x15b1ef328>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1071b54e0>> 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 0x15b1ef328> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1071b54e0>> @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 0x1071b54e0>> 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 0x1071b54e0>> 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 0x000000015ba56548>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000143686f70> 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 0x000000015e1139e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015e1139e0> 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 0x000000014d57d980> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014d57d980> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014d57d980> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014d57d980> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015e1e74a0> 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 0x00000001452e7520> 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 0x106d85680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x106d85660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x106d897b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014d57def8>, <W_TypeObject 'GenericAlias' at 0x15c083520>, ...] 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 0x12518bbb0> 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 0x12518bbb0> 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 0x12518bbb0> 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 0x12518bbb0> 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 0x107564b00>> w_obj = <W_TypeObject 'ellipsis' at 0x12518bbb0> 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 0x12518bbb0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107564b00>> 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 0x12518bbb0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107564b00>> @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 0x107564b00>> 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 0x107564b00>> 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 0x000000014dc215b0>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000015db44570> 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 0x000000014e0d25a0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014e0d25a0> 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 0x000000014cdbdc90> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014cdbdc90> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014cdbdc90> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014cdbdc90> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014e12e1e0> 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 0x000000015bd66bb8> 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 0x10794d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10794d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000125120250>, <W_TypeObject 'GenericAlias' at 0x147895210>, ...] 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 0x14f1b2fa8> 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 0x14f1b2fa8> 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 0x14f1b2fa8> 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 0x14f1b2fa8> 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 0x10764b220>> w_obj = <W_TypeObject 'ellipsis' at 0x14f1b2fa8> 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 0x14f1b2fa8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10764b220>> 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 0x14f1b2fa8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10764b220>> @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 0x10764b220>> 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 0x10764b220>> 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 0x0000000150195a60>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000145b87d80> 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 0x00000001460554a0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001460554a0> 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 0x0000000146dbbef8> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000146dbbef8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000146dbbef8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000146dbbef8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000146060d60> 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 0x000000015e42b280> 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 0x1079cd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1079cd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079d17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000146da24b8>, <W_TypeObject 'GenericAlias' at 0x14e22e6b0>, ...] 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 0x144b65980> 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 0x144b65980> 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 0x144b65980> 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 0x144b65980> 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 0x107fb5230>> w_obj = <W_TypeObject 'ellipsis' at 0x144b65980> 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 0x144b65980>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107fb5230>> 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 0x144b65980> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107fb5230>> @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 0x107fb5230>> 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 0x107fb5230>> 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 0x0000000124276980>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000013153fdf8> 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 0x000000015e3c2960> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015e3c2960> 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 0x000000015e274f00> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015e274f00> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015e274f00> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000015e274f00> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015c5825a0> 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 0x000000012485b398> 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 0x107b4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107b4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107b517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000015e275478>, <W_TypeObject 'GenericAlias' at 0x1461a6b10>, ...] 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 0x1461c9d00> 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 0x1461c9d00> 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 0x1461c9d00> 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 0x1461c9d00> 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 0x10786f9a0>> w_obj = <W_TypeObject 'ellipsis' at 0x1461c9d00> 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 0x1461c9d00>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10786f9a0>> 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 0x1461c9d00> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10786f9a0>> @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 0x10786f9a0>> 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 0x10786f9a0>> 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 0x0000000145cf47a0>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014462af20> 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 0x000000014ec2d160> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014ec2d160> 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 0x0000000110c55280> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000110c55280> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000110c55280> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000110c55280> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000011104eb60> 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 0x00000001273f7d38> 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 0x107d4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107d4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107d517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000110c557f8>, <W_TypeObject 'GenericAlias' at 0x15d8e0a68>, ...] 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 0x15d94bbe8> 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 0x15d94bbe8> 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 0x15d94bbe8> 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 0x15d94bbe8> 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 0x107aa6240>> w_obj = <W_TypeObject 'ellipsis' at 0x15d94bbe8> 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 0x15d94bbe8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107aa6240>> 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 0x15d94bbe8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107aa6240>> @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 0x107aa6240>> 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 0x107aa6240>> 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 0x000000014d4b3bc8>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000150290d40> 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 0x000000014c59b220> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014c59b220> 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 0x000000014c5bee58> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014c5bee58> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014c5bee58> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014c5bee58> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001310ae520> 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 0x00000001462ed830> 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 0x10494d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10494d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1049517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014c5bf3d0>, <W_TypeObject 'GenericAlias' at 0x14b659ec0>, ...] 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 0x1435972b8> 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 0x1435972b8> 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 0x1435972b8> 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 0x1435972b8> 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 0x1071c45e0>> w_obj = <W_TypeObject 'ellipsis' at 0x1435972b8> 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 0x1435972b8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1071c45e0>> 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 0x1435972b8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1071c45e0>> @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 0x1071c45e0>> 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 0x1071c45e0>> 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 0x0000000110b80278>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014369b010> 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 0x000000015b873a20> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015b873a20> 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 0x000000014ce5c2c0> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014ce5c2c0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014ce5c2c0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014ce5c2c0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014bb3f160> 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 0x000000014de7b478> 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 0x106d85680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x106d85660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x106d897b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014ce5c988>, <W_TypeObject 'GenericAlias' at 0x1268607c8>, ...] 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 0x14e9bdef8> 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 0x14e9bdef8> 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 0x14e9bdef8> 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 0x14e9bdef8> 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 0x10749f940>> w_obj = <W_TypeObject 'ellipsis' at 0x14e9bdef8> 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 0x14e9bdef8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10749f940>> 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 0x14e9bdef8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10749f940>> @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 0x10749f940>> 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 0x10749f940>> 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 0x000000015ddbdd30>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000012660a520> 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 0x000000015c4ad2a0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015c4ad2a0> 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 0x0000000146842608> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000146842608> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000146842608> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000146842608> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015bec6e60> 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 0x0000000145023360> 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 0x10794d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10794d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000146842b80>, <W_TypeObject 'GenericAlias' at 0x14c73bc90>, ...] 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 0x123dc5e50> 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 0x123dc5e50> 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 0x123dc5e50> 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 0x123dc5e50> 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 0x107c62230>> w_obj = <W_TypeObject 'ellipsis' at 0x123dc5e50> 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 0x123dc5e50>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107c62230>> 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 0x123dc5e50> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107c62230>> @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 0x107c62230>> 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 0x107c62230>> 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 0x00000001448b3d30>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x000000014cc595b0> 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 0x000000015c600420> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015c600420> 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 0x00000001435f2870> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001435f2870> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001435f2870> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x00000001435f2870> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015c640620> 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 0x00000001258acde8> 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 0x1079cd680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1079cd660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1079d17b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x00000001435f2de8>, <W_TypeObject 'GenericAlias' at 0x1262fe7c8>, ...] 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 0x126330720> 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 0x126330720> 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 0x126330720> 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 0x126330720> 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 0x1078687c0>> w_obj = <W_TypeObject 'ellipsis' at 0x126330720> 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 0x126330720>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1078687c0>> 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 0x126330720> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1078687c0>> @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 0x1078687c0>> 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 0x1078687c0>> 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 0x0000000146ff75b0>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001405fc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000140784860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001482975e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000148297620>] 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 0x0000000144737d80> 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 0x0000000124b1f4a0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000124b1f4a0> 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 0x0000000126d81b78> key = (((True, True, True, True, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000126d81b78> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000126d81b78> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000126d81b78> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000124c47060> 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 0x0000000144365cc8> 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 0x107b4d680>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x107b4d660>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107b517b0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014163df68>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000015bdca288>, <W_TypeObject 'GenericAlias' at 0x14cc3c9c0>, ...] 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 0x145324bf0> 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 0x145324bf0> 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 0x145324bf0> 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 0x145324bf0> 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 0x1078537c0>> w_obj = <W_TypeObject 'ellipsis' at 0x145324bf0> 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 0x145324bf0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1078537c0>> 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 0x145324bf0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1078537c0>> @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 0x1078537c0>> 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 0x1078537c0>> 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 =================================== FAILURES =================================== ________________________ AppTestC.test_call_function_9 _________________________ self = <pypy.interpreter.typedef.W_ObjectObjectUserDictWeakrefable object at 0x00000001591fab80> def test_call_function_9(self): import _all_test_c try: > _all_test_c.test_call_function_9() [/tmp/buildbot-arm64/usession-py3.12-1201/test_c/_test_c.py:594]:4: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ @pytest.mark.xfail( is_ios, reason="For an unknown reason f(1, cast(BInt, 42)) returns 36792864", raises=AssertionError, ) def test_call_function_9(): BInt = new_primitive_type("int") BFunc9 = new_function_type((BInt,), BInt, True) # vararg f = cast(BFunc9, _testfunc(9)) assert f(0) == 0 > assert f(1, cast(BInt, 42)) == 42 E (application-level) AssertionError /tmp/buildbot-arm64/usession-py3.12-1201/test_c/_all_test_c.py:1261: AssertionError _________________ AppTestRecompilerPython.test_dlopen_unicode __________________ self = <pypy.interpreter.typedef.W_ObjectObjectUserDictWeakrefable object at 0x00000001437a9868> def test_dlopen_unicode(self): if not getattr(self, 'extmodU', None): skip("no unicode file name") import _cffi_backend, sys sys.pypy_initfsencoding() # initialize space.sys.filesystemencoding self.fix_path() from re_python_pysrc import ffi > lib = ffi.dlopen(self.extmodU) E (application-level) OSError: Cannot load library /tmp/buildbot-arm64/usession-py3.12-1201/load_caf\xE9.so: "Cannot load library /tmp/buildbot-arm64/usession-py3.12-1201/load_caf\xe9.so: dlopen(/tmp/buildbot-arm64/usession-py3.12-1201/load_caf\xe9.so, 0x0002): tried: '/tmp/buildbot-arm64/usession-py3.12-1201/load_caf\xe9.so' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/tmp/buildbot-arm64/usession-py3.12-1201/load_caf\xe9.so' (no such file), '/tmp/buildbot-arm64/usession-py3.12-1201/load_caf\xe9.so' (no such file), '/private/tmp/buildbot-arm64/usession-py3.12-1201/load_caf\xe9.so' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/private/tmp/buildbot-arm64/usession-py3.12-1201/load_caf\xe9.so' (no such file), '/private/tmp/buildbot-arm64/usession-py3.12-1201/load_caf\xe9.so' (no such file)" [/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/module/_cffi_backend/test/test_re_python.py:139]:8: OSError =========================== short test summary info ============================ FAIL module/_cffi_backend/test/test_c.py::AppTestC::()::test_call_function_9 FAIL module/_cffi_backend/test/test_re_python.py::AppTestRecompilerPython::()::test_dlopen_unicode ======== 2 failed, 329 passed, 13 skipped, 124 error in 888.88 seconds ========= ++ 05:50:09 starting module/_pickle_support/test [62 started in total] __ module/_pickle_support/test [60 done in total, somefailed=False] ___________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 1 items module/_pickle_support/test/apptest__pickle_support.py . ========================== 1 passed in 11.16 seconds =========================== ++ 05:50:21 starting module/_posixsubprocess/test [63 started in total] __ module/_io/test [61 done in total, somefailed=True] ________________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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.................F module/_io/test/test_bufferedio.py .......................................................................ss................................ module/_io/test/test_fileio.py .................................... module/_io/test/test_interp_textio.py ......... =================================== FAILURES =================================== _________________________ test_concurrent_next_at_eof __________________________ tempfile = W_UnicodeObject('/private/tmp/buildbot-arm64/pytest/pytest-of-matti/pytest-578/tempfile') def test_concurrent_next_at_eof(tempfile): # https://github.com/pypy/pypy/issues/5575 # Two threads iterating the same TextIOWrapper over a real fd can race # inside the decode buffer when the underlying read() releases the GIL, # especially right at EOF where DecodeBuffer.reset() nulls out its state. import _thread import time with _io.open(tempfile, 'wb') as w: w.write(b"line\n") f = _io.TextIOWrapper(_io.BufferedReader(_io.FileIO(tempfile, "r"))) it = iter(f) done = [] def worker(): for _ in range(10): try: next(it) except Exception: pass done.append(1) _thread.start_new_thread(worker, ()) _thread.start_new_thread(worker, ()) deadline = time.time() + 15.0 while len(done) < 2: > assert time.time() < deadline, "worker threads hung (see issue 5575)" E (application-level) AssertionError: worker threads hung (see issue 5575) E assert 1788317134.686644 < 1788317133.820093 E + where 1788317134.686644 = <built-in function time>() E + where <built-in function time> = <module 'time' (built-in)>.time module/_io/test/apptest_textio.py:852: AssertionError =========================== short test summary info ============================ FAIL module/_io/test/apptest_textio.py::test_concurrent_next_at_eof ============== 1 failed, 283 passed, 4 skipped in 479.47 seconds =============== ++ 05:51:01 starting module/_pypyjson/test [64 started in total] __ module/_pickle/test [62 done in total, somefailed=False] ___________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 255.47 seconds ==================== ++ 05:51:20 starting module/_random/test [65 started in total] __ module/_random/test [63 done in total, somefailed=False] ___________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 22.23 seconds ========================== ++ 05:51:44 starting module/_rawffi/alt/test [66 started in total] __ module/_rawffi/alt/test [64 done in total, somefailed=False] _______________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 23.05 seconds ===================== ++ 05:52:08 starting module/_rawffi/test [67 started in total] __ module/_pypyjson/test [65 done in total, somefailed=False] _________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 54 items / 1 skipped module/_pypyjson/test/apptest__pypyjson.py .......... module/_pypyjson/test/test__pypyjson.py ............................................ ==================== 54 passed, 1 skipped in 67.17 seconds ===================== ++ 05:52:14 starting module/_socket/test [68 started in total] __ module/_posixsubprocess/test [66 done in total, somefailed=True] ___________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 10 items module/_posixsubprocess/test/apptest_subprocess.py ........F module/_posixsubprocess/test/test_ztranslation.py . =================================== FAILURES =================================== _____________________________ test_restore_signals _____________________________ def test_restore_signals(): import posix as os # Copied from lib-python/3/subprocess._execute_child # when calling subprocess.check_output(['cat', '/proc/self/status'], # restore_signals=True, universal_newlines=True) def check_output(restore_signals): c2pread, c2pwrite = os.pipe() errpipe_read, errpipe_write = os.pipe() try: low_fds_to_close = [] while errpipe_write < 3: low_fds_to_close.append(errpipe_write) errpipe_write = os.dup(errpipe_write) for low_fd in low_fds_to_close: os.close(low_fd) args = [b'cat', b'/proc/self/status'] executable_list=[b'/usr/bin/cat'] close_fds = True fds_to_keep = (errpipe_write,) cwd = None env_list = None p2cread = p2cwrite = -1 errread = errwrite = umask = -1 call_setsid = False pgid_to_set = -1 preexec_fn = None gid = gids = uid = None pid = _posixsubprocess.fork_exec(args, executable_list, close_fds, fds_to_keep, cwd, env_list, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, errpipe_read, errpipe_write, restore_signals, call_setsid, pgid_to_set, gid, gids, uid, umask, preexec_fn, subprocess._USE_VFORK) os.close(errpipe_write) # Wait for exec to fail or succeed; possibly raising an # exception (limited in size) errpipe_data = bytearray() while True: part = os.read(errpipe_read, 50000) errpipe_data += part if not part or len(errpipe_data) > 50000: break if errpipe_data: newpid, sts = os.waitpid(pid, 0) raise RuntimeError('running commande returned %s' % sts) out = os.read(c2pread, 50000) finally: os.close(c2pwrite) os.close(c2pread) os.close(errpipe_read) return out sig_ign_mask1 = '' sig_ign_mask2 = '' > for line in check_output(True).splitlines(): module/_posixsubprocess/test/apptest_subprocess.py:282: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ restore_signals = W_BoolObject(True) def check_output(restore_signals): c2pread, c2pwrite = os.pipe() errpipe_read, errpipe_write = os.pipe() try: low_fds_to_close = [] while errpipe_write < 3: low_fds_to_close.append(errpipe_write) errpipe_write = os.dup(errpipe_write) for low_fd in low_fds_to_close: os.close(low_fd) args = [b'cat', b'/proc/self/status'] executable_list=[b'/usr/bin/cat'] close_fds = True fds_to_keep = (errpipe_write,) cwd = None env_list = None p2cread = p2cwrite = -1 errread = errwrite = umask = -1 call_setsid = False pgid_to_set = -1 preexec_fn = None gid = gids = uid = None pid = _posixsubprocess.fork_exec(args, executable_list, close_fds, fds_to_keep, cwd, env_list, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, errpipe_read, errpipe_write, restore_signals, call_setsid, pgid_to_set, gid, gids, uid, umask, preexec_fn, subprocess._USE_VFORK) os.close(errpipe_write) # Wait for exec to fail or succeed; possibly raising an # exception (limited in size) errpipe_data = bytearray() while True: part = os.read(errpipe_read, 50000) errpipe_data += part if not part or len(errpipe_data) > 50000: break if errpipe_data: newpid, sts = os.waitpid(pid, 0) > raise RuntimeError('running commande returned %s' % sts) E (application-level) RuntimeError: running commande returned 65280 module/_posixsubprocess/test/apptest_subprocess.py:272: RuntimeError =========================== short test summary info ============================ FAIL module/_posixsubprocess/test/apptest_subprocess.py::test_restore_signals ===================== 1 failed, 9 passed in 131.92 seconds ===================== ++ 05:52:39 starting module/_sre/test [69 started in total] __ module/_rawffi/test [67 done in total, somefailed=False] ___________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 88.00 seconds ===================== n: 2 Arg 0: 3 Arg 1: 15 ++ 05:53:43 starting module/_vmprof/test [70 started in total] __ module/_vmprof/test [68 done in total, somefailed=False] ___________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 44.29 seconds ===================== ++ 05:54:34 starting module/_warnings/test [71 started in total] __ module/_warnings/test [69 done in total, somefailed=False] _________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 36.19 seconds ===================== ++ 05:55:12 starting module/_weakref/test [72 started in total] __ module/_sre/test [70 done in total, somefailed=False] ______________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 163 items module/_sre/test/apptest_sre.py ......................................................................................................... module/_sre/test/test_app_sre.py .............................. module/_sre/test/test_sre_buf.py ............................ ========================= 163 passed in 168.25 seconds ========================= ++ 05:55:33 starting module/_winreg/test [73 started in total] __ module/_winreg/test [71 done in total, somefailed=False] ___________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 0 items / 1 skipped ========================== 1 skipped in 0.10 seconds =========================== ++ 05:55:34 starting module/array/test [74 started in total] __ module/_weakref/test [72 done in total, somefailed=False] __________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 43 items module/_weakref/test/apptest_weakref.py ........................................... ========================== 43 passed in 79.35 seconds ========================== ++ 05:56:32 starting module/atexit/test [75 started in total] __ module/atexit/test [73 done in total, somefailed=False] ____________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 2 items module/atexit/test/apptest_atexit.py .. ========================== 2 passed in 21.54 seconds =========================== ++ 05:56:56 starting module/binascii/test [76 started in total] __ module/binascii/test [74 done in total, somefailed=False] __________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 18 items module/binascii/test/test_binascii.py .................. ========================== 18 passed in 25.38 seconds ========================== ++ 05:57:24 starting module/bz2/test [77 started in total] __ module/array/test [75 done in total, somefailed=False] _____________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 118.77 seconds ==================== ++ 05:57:37 starting module/cmath/test [78 started in total] __ module/cmath/test [76 done in total, somefailed=False] _____________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 18 items module/cmath/test/test_cmath.py .................. ========================== 18 passed in 11.93 seconds ========================== ++ 05:57:49 starting module/cpyext/test/test_api.py [79 started in total] __ module/cpyext/test/test_api.py [77 done in total, somefailed=True] _________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 0x100e43780>> 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 0x12df39c40>> 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.62 seconds ====================== ++ 05:58:17 starting module/cpyext/test/test_arraymodule.py [80 started in total] __ module/_socket/test [78 done in total, somefailed=True] ____________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 87 items module/_socket/test/apptest_socket.py .....................ss..s............s.ss...........F...sssss module/_socket/test/test_sock_app.py ....................s... module/_socket/test/test_ztranslation.py . =================================== FAILURES =================================== ___________________________ test_tcp_bytearray_name ____________________________ def test_tcp_bytearray_name(): import _socket as socket if not hasattr(socket, 'AF_UNIX'): pytest.skip('AF_UNIX not supported.') s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) > s.bind(bytearray(b"\x00python\x00test\x00")) E (application-level) FileNotFoundError: [Errno 2] No such file or directory module/_socket/test/apptest_socket.py:847: OSError =========================== short test summary info ============================ FAIL module/_socket/test/apptest_socket.py::test_tcp_bytearray_name ============== 1 failed, 74 passed, 12 skipped in 377.07 seconds =============== ++ 05:58:37 starting module/cpyext/test/test_async_iter.py [81 started in total] __ module/cpyext/test/test_async_iter.py [79 done in total, somefailed=True] __ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 0x0000000149727ad8>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001381bc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000109687560>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118287620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118287660>] 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 0x0000000109687560>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118287620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118287660>] 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 0x0000000149735df8> 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 0x0000000149720520> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000149720520> 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 0x0000000149730f00> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000149730f00> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000149730f00> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000149730f00> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001497b9a60> 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 0x0000000149802a30> 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 0x10174d698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10174d678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1017517c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000001396de1a8>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000149731478>, <W_TypeObject 'GenericAlias' at 0x1097c1be8>, ...] 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 0x1499deec8> 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 0x1499deec8> 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 0x1499deec8> 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 0x1499deec8> 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 0x101636260>> w_obj = <W_TypeObject 'ellipsis' at 0x1499deec8> 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 0x1499deec8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x101636260>> 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 0x1499deec8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x101636260>> @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 0x101636260>> 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 0x101636260>> 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 0x0000000149512908>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001381bc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000109687560>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118287620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118287660>] 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 0x0000000109687560>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118287620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118287660>] 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 0x0000000109084e58> 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 0x0000000128564de0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000128564de0> 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 0x00000001285405d0> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001285405d0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001285405d0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x00000001285405d0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001397646a0> 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 0x0000000139ea1e50> 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 0x1017cd698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1017cd678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1017d17c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000001396de1a8>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000128540d08>, <W_TypeObject 'GenericAlias' at 0x1495a56a8>, ...] 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 0x149a23a98> 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 0x149a23a98> 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 0x149a23a98> 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 0x149a23a98> 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 0x101431800>> w_obj = <W_TypeObject 'ellipsis' at 0x149a23a98> 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 0x149a23a98>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x101431800>> 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 0x149a23a98> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x101431800>> @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 0x101431800>> 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 0x101431800>> 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 0x00000001497e9cb8>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001381bc9c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000109687560>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118287620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118287660>] 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 0x0000000109687560>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118287620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118287660>] 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 0x000000013ae83268> 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 0x000000013aee3de0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000013aee3de0> 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 0x000000013af5e758> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000013af5e758> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000013af5e758> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000013af5e758> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000013af737e0> 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 0x0000000119b4a7c8> 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 0x10204d698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10204d678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1020517c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000001396de1a8>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000013af5ecd0>, <W_TypeObject 'GenericAlias' at 0x13b0c5bb0>, ...] 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 0x13b119280> 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 0x13b119280> 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 0x13b119280> 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 0x13b119280> 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 0x1014c82b0>> w_obj = <W_TypeObject 'ellipsis' at 0x13b119280> 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 0x13b119280>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1014c82b0>> 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 0x13b119280> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1014c82b0>> @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 0x1014c82b0>> 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 0x1014c82b0>> 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 17.09 seconds =========================== ++ 05:59:09 starting module/cpyext/test/test_boolobject.py [82 started in total] __ module/cpyext/test/test_boolobject.py [80 done in total, somefailed=True] __ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 0x100e80560>> 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 0x0000000150690020>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x000000012802c9f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000109269ca0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000108287620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000108287660>] 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 0x0000000109269ca0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000108287620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000108287660>] 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 0x0000000129c94908> 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 0x0000000129c86160> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000129c86160> 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 0x000000013b01a3a0> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000013b01a3a0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000013b01a3a0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000013b01a3a0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000129c87ce0> 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 0x000000015043ea30> 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 0x100ca96a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x100ca9688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x100cad7d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000012928c288>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000013b04c678>, <W_TypeObject 'GenericAlias' at 0x1494769c0>, ...] 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 0x1090e2560> 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 0x1090e2560> 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 0x1090e2560> 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 0x1090e2560> 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 0x1005efbc0>> w_obj = <W_TypeObject 'ellipsis' at 0x1090e2560> 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 0x1090e2560>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1005efbc0>> 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 0x1090e2560> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1005efbc0>> @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 0x1005efbc0>> 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 0x1005efbc0>> 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 0x0000000109455f88>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x000000012802c9f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000109269ca0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000108287620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000108287660>] 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 0x0000000109269ca0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000108287620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000108287660>] 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 0x000000013a7f7f88> 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 0x0000000109c548e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000109c548e0> 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 0x0000000109c4edb0> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000109c4edb0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000109c4edb0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000109c4edb0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000109c55fa0> 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 0x0000000149a55360> 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 0x10224d6a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10224d688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1022517d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000012928c288>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000109c4f328>, <W_TypeObject 'GenericAlias' at 0x149babd00>, ...] 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 0x149c09088> 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 0x149c09088> 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 0x149c09088> 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 0x149c09088> 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 0x1021340e0>> w_obj = <W_TypeObject 'ellipsis' at 0x149c09088> 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 0x149c09088>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1021340e0>> 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 0x149c09088> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1021340e0>> @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 0x1021340e0>> 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 0x1021340e0>> 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 0x000000010b172e30>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x000000012802c9f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000109269ca0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000108287620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000108287660>] 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 0x0000000109269ca0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000108287620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000108287660>] 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 0x000000012a6188e0> 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 0x000000012a634ce0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000012a634ce0> 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 0x000000012a64ad78> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000012a64ad78> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000012a64ad78> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000012a64ad78> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000010b22c3e0> 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 0x000000012a6c6838> 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 0x1022cd6a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1022cd688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1022d17d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000012928c288>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000012a64b2f0>, <W_TypeObject 'GenericAlias' at 0x129718c60>, ...] 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 0x108f9b2f0> 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 0x108f9b2f0> 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 0x108f9b2f0> 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 0x108f9b2f0> 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 0x134edf510>> w_obj = <W_TypeObject 'ellipsis' at 0x108f9b2f0> 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 0x108f9b2f0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x134edf510>> 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 0x108f9b2f0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x134edf510>> @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 0x134edf510>> 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 0x134edf510>> 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 21.66 seconds =========================== ++ 05:59:48 starting module/cpyext/test/test_borrow.py [83 started in total] __ module/cpyext/test/test_arraymodule.py [81 done in total, somefailed=True] _ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 0x0000000149394278>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x000000012004c9f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x000000014939d3f8> 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 0x00000001493eb160> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001493eb160> 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 0x00000001493fa1e0> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001493fa1e0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001493fa1e0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x00000001493fa1e0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001414e9960> 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 0x00000001584718a0> 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 0x103e4d698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x103e4d678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x103e517c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000140fd8918>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x00000001493fa758>, <W_TypeObject 'GenericAlias' at 0x131d93590>, ...] 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 0x121c5a4b8> 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 0x121c5a4b8> 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 0x121c5a4b8> 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 0x121c5a4b8> 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 0x11ee78260>> w_obj = <W_TypeObject 'ellipsis' at 0x121c5a4b8> 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 0x121c5a4b8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11ee78260>> 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 0x121c5a4b8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11ee78260>> @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 0x11ee78260>> 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 0x11ee78260>> 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 0x0000000110402b60>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x000000012004c9f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x0000000120c2f8a8> 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 0x000000011045f420> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000011045f420> 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 0x00000001218329c0> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001218329c0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001218329c0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x00000001218329c0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000149540ba0> 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 0x0000000131c8bd00> 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 0x103ecd698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x103ecd678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x103ed17c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000140fd8918>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000121832f38>, <W_TypeObject 'GenericAlias' at 0x1325e38d8>, ...] 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 0x13226bc20> 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 0x13226bc20> 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 0x13226bc20> 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 0x13226bc20> 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 0x10eff3b40>> w_obj = <W_TypeObject 'ellipsis' at 0x13226bc20> 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 0x13226bc20>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10eff3b40>> 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 0x13226bc20> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10eff3b40>> @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 0x10eff3b40>> 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 0x10eff3b40>> 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 0x00000001584a2818>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x000000012004c9f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x00000001423cc7f0> 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 0x00000001423b7ee0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001423b7ee0> 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 0x0000000132b22988> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000132b22988> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000132b22988> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000132b22988> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000132b317a0> 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 0x00000001502c9ad0> 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 0x103f4d698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x103f4d678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x103f517c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000140fd8918>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000132b22f00>, <W_TypeObject 'GenericAlias' at 0x149914c28>, ...] 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 0x132d62bb8> 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 0x132d62bb8> 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 0x132d62bb8> 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 0x132d62bb8> 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 0x102f81200>> w_obj = <W_TypeObject 'ellipsis' at 0x132d62bb8> 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 0x132d62bb8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102f81200>> 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 0x132d62bb8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102f81200>> @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 0x102f81200>> 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 0x102f81200>> 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 0x0000000142482020>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x000000012004c9f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x00000001239b73d0> 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 0x0000000123a64420> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000123a64420> 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 0x0000000123a60b48> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000123a60b48> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000123a60b48> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000123a60b48> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000123a65aa0> 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 0x0000000148f30a30> 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 0x103ecd698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x103ecd678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x103ed17c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000140fd8918>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000123a61360>, <W_TypeObject 'GenericAlias' at 0x131bc0870>, ...] 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 0x141370640> 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 0x141370640> 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 0x141370640> 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 0x141370640> 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 0x12eff0730>> w_obj = <W_TypeObject 'ellipsis' at 0x141370640> 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 0x141370640>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x12eff0730>> 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 0x141370640> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x12eff0730>> @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 0x12eff0730>> 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 0x12eff0730>> 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 0x00000001494b85c0>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x000000012004c9f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x0000000132324250> 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 0x00000001419c0f60> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001419c0f60> 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 0x0000000141991360> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000141991360> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000141991360> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000141991360> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001329f09a0> 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 0x000000012211da60> 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 0x103fcd698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x103fcd678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x103fd17c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000140fd8918>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x00000001419918d8>, <W_TypeObject 'GenericAlias' at 0x121fb8170>, ...] 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 0x122033478> 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 0x122033478> 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 0x122033478> 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 0x122033478> 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 0x102ec4670>> w_obj = <W_TypeObject 'ellipsis' at 0x122033478> 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 0x122033478>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102ec4670>> 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 0x122033478> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102ec4670>> @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 0x102ec4670>> 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 0x102ec4670>> 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 0x00000001424a96a0>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x000000012004c9f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x00000001337eecf0> 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 0x0000000133851520> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000133851520> 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 0x000000013387eaa0> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000013387eaa0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000013387eaa0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000013387eaa0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000149c8ade0> 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 0x0000000133998608> 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 0x10494d698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10494d678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1049517c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000140fd8918>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000013387f018>, <W_TypeObject 'GenericAlias' at 0x148ec7328>, ...] 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 0x121321520> 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 0x121321520> 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 0x121321520> 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 0x121321520> 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 0x102f348f0>> w_obj = <W_TypeObject 'ellipsis' at 0x121321520> 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 0x121321520>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102f348f0>> 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 0x121321520> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102f348f0>> @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 0x102f348f0>> 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 0x102f348f0>> 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 0x0000000110403538>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x000000012004c9f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x0000000131d72b38> 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 0x0000000141a109a0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000141a109a0> 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 0x00000001419fdfa0> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001419fdfa0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001419fdfa0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x00000001419fdfa0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001321061e0> 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 0x000000013210d4b0> 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 0x103ecd698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x103ecd678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x103ed17c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000140fd8918>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000141a08560>, <W_TypeObject 'GenericAlias' at 0x121959e50>, ...] 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 0x141b773d0> 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 0x141b773d0> 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 0x141b773d0> 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 0x141b773d0> 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 0x10ee5dfb0>> w_obj = <W_TypeObject 'ellipsis' at 0x141b773d0> 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 0x141b773d0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10ee5dfb0>> 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 0x141b773d0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10ee5dfb0>> @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 0x10ee5dfb0>> 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 0x10ee5dfb0>> 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 0x000000015846cb60>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x000000012004c9f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x000000013306bcb8> 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 0x0000000123198c20> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000123198c20> 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 0x0000000122ed3328> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000122ed3328> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000122ed3328> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000122ed3328> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000012383c4a0> 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 0x0000000122637830> 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 0x103f4d698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x103f4d678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x103f517c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000140fd8918>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000122ed38a0>, <W_TypeObject 'GenericAlias' at 0x141a36c28>, ...] 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 0x131538288> 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 0x131538288> 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 0x131538288> 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 0x131538288> 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 0x102d061d0>> w_obj = <W_TypeObject 'ellipsis' at 0x131538288> 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 0x131538288>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102d061d0>> 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 0x131538288> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102d061d0>> @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 0x102d061d0>> 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 0x102d061d0>> 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 0x00000001339ade20>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x000000012004c9f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x0000000131d21330> 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 0x00000001323cef60> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001323cef60> 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 0x00000001229e1520> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001229e1520> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001229e1520> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x00000001229e1520> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001586426a0> 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 0x0000000149b8b0f8> 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 0x103ecd698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x103ecd678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x103ed17c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000140fd8918>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x00000001229e1a98>, <W_TypeObject 'GenericAlias' at 0x149cb7c58>, ...] 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 0x133908e90> 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 0x133908e90> 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 0x133908e90> 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 0x133908e90> 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 0x102ebe0e0>> w_obj = <W_TypeObject 'ellipsis' at 0x133908e90> 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 0x133908e90>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102ebe0e0>> 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 0x133908e90> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102ebe0e0>> @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 0x102ebe0e0>> 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 0x102ebe0e0>> 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 0x00000001494ee458>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x000000012004c9f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x00000001227171f0> 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 0x00000001226d3f60> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001226d3f60> 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 0x00000001226c5d70> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001226c5d70> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001226c5d70> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x00000001226c5d70> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000012356d560> 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 0x0000000130084100> 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 0x103fcd698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x103fcd678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x103fd17c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000140fd8918>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000123540330>, <W_TypeObject 'GenericAlias' at 0x13182eb10>, ...] 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 0x148f1e3a0> 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 0x148f1e3a0> 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 0x148f1e3a0> 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 0x148f1e3a0> 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 0x102936160>> w_obj = <W_TypeObject 'ellipsis' at 0x148f1e3a0> 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 0x148f1e3a0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102936160>> 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 0x148f1e3a0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102936160>> @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 0x102936160>> 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 0x102936160>> 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 0x00000001339ad880>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x000000012004c9f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x0000000131d5c4f8> 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 0x0000000122415960> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000122415960> 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 0x000000012385ae58> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000012385ae58> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000012385ae58> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000012385ae58> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001223cf4a0> 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 0x0000000123701d70> 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 0x103ecd698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x103ecd678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x103ed17c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000140fd8918>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000012385b3d0>, <W_TypeObject 'GenericAlias' at 0x1498f4598>, ...] 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 0x131eee4f0> 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 0x131eee4f0> 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 0x131eee4f0> 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 0x131eee4f0> 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 0x103c54040>> w_obj = <W_TypeObject 'ellipsis' at 0x131eee4f0> 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 0x131eee4f0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x103c54040>> 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 0x131eee4f0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x103c54040>> @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 0x103c54040>> 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 0x103c54040>> 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 0x0000000149518368>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x000000012004c9f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x0000000122568c78> 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 0x00000001325f62e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001325f62e0> 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 0x0000000122595a28> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000122595a28> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000122595a28> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000122595a28> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001325f78a0> 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 0x00000001416b8c28> 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 0x103f4d698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x103f4d678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x103f517c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000140fd8918>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000122595fa0>, <W_TypeObject 'GenericAlias' at 0x122bf7440>, ...] 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 0x1229e01e0> 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 0x1229e01e0> 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 0x1229e01e0> 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 0x1229e01e0> 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 0x102f1b150>> w_obj = <W_TypeObject 'ellipsis' at 0x1229e01e0> 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 0x1229e01e0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102f1b150>> 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 0x1229e01e0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102f1b150>> @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 0x102f1b150>> 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 0x102f1b150>> 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 0x00000001410fea70>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x000000012004c9f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x00000001492e9b50> 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 0x000000014987f520> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014987f520> 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 0x0000000123743050> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000123743050> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000123743050> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000123743050> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014987b020> 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 0x00000001329d6720> 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 0x103ecd698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x103ecd678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x103ed17c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000140fd8918>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000123743868>, <W_TypeObject 'GenericAlias' at 0x1495cabf0>, ...] 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 0x13236e560> 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 0x13236e560> 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 0x13236e560> 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 0x13236e560> 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 0x1029fe200>> w_obj = <W_TypeObject 'ellipsis' at 0x13236e560> 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 0x13236e560>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1029fe200>> 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 0x13236e560> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1029fe200>> @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 0x1029fe200>> 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 0x1029fe200>> 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 0x0000000149395cb8>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x000000012004c9f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x00000001228f0570> 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 0x00000001228d3d60> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001228d3d60> 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 0x00000001229156e0> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001229156e0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001229156e0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x00000001229156e0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000121dd94e0> 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 0x0000000122768100> 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 0x103fcd698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x103fcd678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x103fd17c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000140fd8918>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000122915a28>, <W_TypeObject 'GenericAlias' at 0x122ca8fa8>, ...] 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 0x132499248> 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 0x132499248> 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 0x132499248> 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 0x132499248> 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 0x103c89b50>> w_obj = <W_TypeObject 'ellipsis' at 0x132499248> 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 0x132499248>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x103c89b50>> 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 0x132499248> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x103c89b50>> @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 0x103c89b50>> 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 0x103c89b50>> 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 0x00000001416ad6a0>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x000000012004c9f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x00000001217a4bb0> 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 0x0000000122011a20> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000122011a20> 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 0x000000015862d2f0> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015862d2f0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015862d2f0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000015862d2f0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000132389160> 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 0x0000000121971a28> 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 0x103ecd698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x103ecd678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x103ed17c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000140fd8918>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000015862d868>, <W_TypeObject 'GenericAlias' at 0x121e28e20>, ...] 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 0x132e4b910> 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 0x132e4b910> 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 0x132e4b910> 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 0x132e4b910> 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 0x10efc6ba0>> w_obj = <W_TypeObject 'ellipsis' at 0x132e4b910> 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 0x132e4b910>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10efc6ba0>> 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 0x132e4b910> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10efc6ba0>> @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 0x10efc6ba0>> 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 0x10efc6ba0>> 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 0x00000001217d7178>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x000000012004c9f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x00000001334f2d90> 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 0x0000000123867e20> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000123867e20> 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 0x0000000123853168> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000123853168> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000123853168> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000123853168> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000013226fce0> 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 0x00000001585a40c8> 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 0x103f4d698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x103f4d678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x103f517c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000140fd8918>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000013227aa68>, <W_TypeObject 'GenericAlias' at 0x123a163a0>, ...] 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 0x123a059b8> 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 0x123a059b8> 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 0x123a059b8> 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 0x123a059b8> 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 0x102eb81d0>> w_obj = <W_TypeObject 'ellipsis' at 0x123a059b8> 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 0x123a059b8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102eb81d0>> 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 0x123a059b8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102eb81d0>> @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 0x102eb81d0>> 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 0x102eb81d0>> 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 0x0000000122286cc8>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x000000012004c9f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x0000000134280660> 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 0x000000013428c520> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000013428c520> 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 0x0000000134288950> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000134288950> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000134288950> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000134288950> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000013428ce20> 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 0x000000014161cf38> 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 0x103ecd698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x103ecd678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x103ed17c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000140fd8918>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000134288ec8>, <W_TypeObject 'GenericAlias' at 0x141325360>, ...] 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 0x1580e0020> 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 0x1580e0020> 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 0x1580e0020> 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 0x1580e0020> 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 0x12efbb400>> w_obj = <W_TypeObject 'ellipsis' at 0x1580e0020> 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 0x1580e0020>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x12efbb400>> 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 0x1580e0020> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x12efbb400>> @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 0x12efbb400>> 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 0x12efbb400>> 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 0x0000000121e60728>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x000000012004c9f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x000000012183eaa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140287460>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001402874a0>] 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 0x00000001320dcc28> 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 0x0000000133917a20> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000133917a20> 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 0x0000000149a59088> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000149a59088> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000149a59088> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000149a59088> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000133941620> 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 0x00000001229fcf00> 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 0x103f4d698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x103f4d678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x103f517c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000140fd8918>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000149a59600>, <W_TypeObject 'GenericAlias' at 0x1416d7478>, ...] 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 0x1416ba950> 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 0x1416ba950> 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 0x1416ba950> 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 0x1416ba950> 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 0x103d69e90>> w_obj = <W_TypeObject 'ellipsis' at 0x1416ba950> 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 0x1416ba950>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x103d69e90>> 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 0x1416ba950> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x103d69e90>> @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 0x103d69e90>> 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 0x103d69e90>> 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 94.83 seconds =========================== ++ 06:00:06 starting module/cpyext/test/test_buffer.py [84 started in total] __ module/cpyext/test/test_borrow.py [82 done in total, somefailed=True] ______ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 0x0000000119af45c0>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001488a6950> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000149e5b2a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118209420>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118209460>] 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 0x0000000149e5b2a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118209420>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118209460>] 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 0x0000000119b0a2f0> 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 0x0000000119acb1e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000119acb1e0> 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 0x0000000119b08410> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000119b08410> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000119b08410> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000119b08410> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001091ccb60> 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 0x0000000119c6e5d0> 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 0x10054d6a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10054d688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1005517d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000001489cfef8>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000119b08988>, <W_TypeObject 'GenericAlias' at 0x109365130>, ...] 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 0x119e191d8> 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 0x119e191d8> 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 0x119e191d8> 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 0x119e191d8> 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 0x100afc510>> w_obj = <W_TypeObject 'ellipsis' at 0x119e191d8> 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 0x119e191d8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x100afc510>> 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 0x119e191d8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x100afc510>> @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 0x100afc510>> 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 0x100afc510>> 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 0x000000011a0d51f0>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001488a6950> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000149e5b2a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118209420>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118209460>] 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 0x0000000149e5b2a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118209420>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118209460>] 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 0x00000001096a4e08> 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 0x00000001192b0720> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001192b0720> 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 0x0000000118fdfbe8> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000118fdfbe8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000118fdfbe8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000118fdfbe8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000129782920> 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 0x00000001194303d8> 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 0x10204d6a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10204d688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1020517d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000001489cfef8>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000118feab10>, <W_TypeObject 'GenericAlias' at 0x108f48cd0>, ...] 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 0x108fe9a28> 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 0x108fe9a28> 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 0x108fe9a28> 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 0x108fe9a28> 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 0x110fcfd40>> w_obj = <W_TypeObject 'ellipsis' at 0x108fe9a28> 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 0x108fe9a28>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110fcfd40>> 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 0x108fe9a28> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110fcfd40>> @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 0x110fcfd40>> 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 0x110fcfd40>> 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 0x00000001091ad790>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001488a6950> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000149e5b2a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118209420>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118209460>] 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 0x0000000149e5b2a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118209420>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118209460>] 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 0x000000014a186958> 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 0x000000011aa428e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000011aa428e0> 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 0x000000011aa4c838> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000011aa4c838> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000011aa4c838> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000011aa4c838> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000011ab083a0> 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 0x0000000109c63910> 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 0x1020cd6a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1020cd688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1020d17d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000001489cfef8>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000011aa4cdb0>, <W_TypeObject 'GenericAlias' at 0x14a990678>, ...] 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 0x14a9d9c90> 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 0x14a9d9c90> 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 0x14a9d9c90> 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 0x14a9d9c90> 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 0x100cd5030>> w_obj = <W_TypeObject 'ellipsis' at 0x14a9d9c90> 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 0x14a9d9c90>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x100cd5030>> 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 0x14a9d9c90> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x100cd5030>> @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 0x100cd5030>> 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 0x100cd5030>> 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 16.20 seconds =========================== ++ 06:00:20 starting module/cpyext/test/test_bytearrayobject.py [85 started in total] __ module/cpyext/test/test_buffer.py [83 done in total, somefailed=True] ______ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 0x0000000129a511f0>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x000000012804c9f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000013992eb60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118299420>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118299460>] 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 0x000000013992eb60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118299420>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118299460>] 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 0x0000000129a6bd08> 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 0x0000000129a80260> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000129a80260> 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 0x0000000129a6dbe8> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000129a6dbe8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000129a6dbe8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000129a6dbe8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000129b024e0> 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 0x0000000150980b48> 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 0x10484d698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10484d678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1048517c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000001409141a8>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000129a861a8>, <W_TypeObject 'GenericAlias' at 0x129b8b910>, ...] 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 0x139ea1408> 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 0x139ea1408> 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 0x139ea1408> 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 0x139ea1408> 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 0x104e86440>> w_obj = <W_TypeObject 'ellipsis' at 0x139ea1408> 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 0x139ea1408>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104e86440>> 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 0x139ea1408> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104e86440>> @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 0x104e86440>> 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 0x104e86440>> 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 0x00000001395e65c0>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x000000012804c9f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000013992eb60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118299420>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118299460>] 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 0x000000013992eb60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118299420>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118299460>] 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 0x0000000140cc19e8> 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 0x0000000140fcb760> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000140fcb760> 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 0x0000000139d14988> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000139d14988> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000139d14988> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000139d14988> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001296ed060> 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 0x0000000141237d70> 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 0x104ca9698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x104ca9678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104cad7c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000001409141a8>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000139d1ec60>, <W_TypeObject 'GenericAlias' at 0x1418b0410>, ...] 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 0x140b026e8> 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 0x140b026e8> 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 0x140b026e8> 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 0x140b026e8> 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 0x104d87590>> w_obj = <W_TypeObject 'ellipsis' at 0x140b026e8> 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 0x140b026e8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104d87590>> 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 0x140b026e8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104d87590>> @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 0x104d87590>> 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 0x104d87590>> 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 0x0000000129b44890>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x000000012804c9f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000013992eb60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118299420>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118299460>] 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 0x000000013992eb60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118299420>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118299460>] 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 0x000000014198c250> 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 0x000000014198e1a0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014198e1a0> 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 0x000000013a5115c8> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000013a5115c8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000013a5115c8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000013a5115c8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000014198f9e0> 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 0x000000015809c800> 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 0x10624d698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10624d678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1062517c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000001409141a8>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000013a511b40>, <W_TypeObject 'GenericAlias' at 0x13a740528>, ...] 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 0x12a5e8598> 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 0x12a5e8598> 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 0x12a5e8598> 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 0x12a5e8598> 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 0x10604ad40>> w_obj = <W_TypeObject 'ellipsis' at 0x12a5e8598> 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 0x12a5e8598>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10604ad40>> 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 0x12a5e8598> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10604ad40>> @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 0x10604ad40>> 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 0x10604ad40>> 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 0x0000000142505790>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x000000012804c9f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000013992eb60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118299420>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118299460>] 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 0x000000013992eb60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118299420>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118299460>] 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 0x000000012aeb1f60> 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 0x000000012afd2be0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000012afd2be0> 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 0x000000012afdafe0> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000012afdafe0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000012afdafe0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000012afdafe0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000141ba3b60> 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 0x0000000170059a98> 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 0x104ca9698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x104ca9678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104cad7c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000001409141a8>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000012afdbbb0>, <W_TypeObject 'GenericAlias' at 0x139848aa0>, ...] 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 0x119b61600> 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 0x119b61600> 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 0x119b61600> 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 0x119b61600> 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 0x104d0d010>> w_obj = <W_TypeObject 'ellipsis' at 0x119b61600> 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 0x119b61600>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104d0d010>> 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 0x119b61600> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104d0d010>> @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 0x104d0d010>> 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 0x104d0d010>> 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 0x0000000139d2b970>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x000000012804c9f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000013992eb60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118299420>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118299460>] 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 0x000000013992eb60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118299420>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118299460>] 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 0x0000000129d05ad8> 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 0x000000011ab4a820> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000011ab4a820> 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 0x000000011ab4ede8> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000011ab4ede8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000011ab4ede8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000011ab4ede8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001418a6020> 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 0x0000000141bab948> 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 0x1062cd698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1062cd678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1062d17c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000001409141a8>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000011ab4f360>, <W_TypeObject 'GenericAlias' at 0x1583b1788>, ...] 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 0x15838d4b0> 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 0x15838d4b0> 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 0x15838d4b0> 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 0x15838d4b0> 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 0x104da2b10>> w_obj = <W_TypeObject 'ellipsis' at 0x15838d4b0> 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 0x15838d4b0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104da2b10>> 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 0x15838d4b0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104da2b10>> @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 0x104da2b10>> 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 0x104da2b10>> 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 0x0000000142693d30>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x000000012804c9f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000013992eb60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118299420>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118299460>] 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 0x000000013992eb60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118299420>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118299460>] 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 0x0000000142a15510> 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 0x0000000142a93da0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000142a93da0> 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 0x0000000142ad2db0> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000142ad2db0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000142ad2db0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000142ad2db0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000011aa134e0> 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 0x000000011aa898a0> 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 0x10644d698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10644d678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1064517c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000001409141a8>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000142ad3328>, <W_TypeObject 'GenericAlias' at 0x1395f8448>, ...] 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 0x140ad50f8> 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 0x140ad50f8> 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 0x140ad50f8> 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 0x140ad50f8> 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 0x104f351b0>> w_obj = <W_TypeObject 'ellipsis' at 0x140ad50f8> 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 0x140ad50f8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104f351b0>> 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 0x140ad50f8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104f351b0>> @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 0x104f351b0>> 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 0x104f351b0>> 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 32.95 seconds =========================== ++ 06:00:58 starting module/cpyext/test/test_bytesobject.py [86 started in total] __ module/cpyext/test/test_bytearrayobject.py [84 done in total, somefailed=True] ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 0x00000001199b2548>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001382549f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000129ef2f20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118020ae0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118020b20>] 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 0x0000000129ef2f20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118020ae0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118020b20>] 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 0x00000001199b5560> 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 0x0000000119963d60> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000119963d60> 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 0x00000001199bb788> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001199bb788> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001199bb788> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x00000001199bb788> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000129fa53e0> 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 0x0000000139627830> 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 0x104c91698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x104c91678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104c957c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000138f4b9b8>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x00000001199bbd00>, <W_TypeObject 'GenericAlias' at 0x12a165e50>, ...] 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 0x12a2a5398> 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 0x12a2a5398> 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 0x12a2a5398> 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 0x12a2a5398> 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 0x1047c9240>> w_obj = <W_TypeObject 'ellipsis' at 0x12a2a5398> 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 0x12a2a5398>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1047c9240>> 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 0x12a2a5398> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1047c9240>> @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 0x1047c9240>> 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 0x1047c9240>> 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 0x0000000151b55970>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001382549f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000129ef2f20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118020ae0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118020b20>] 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 0x0000000129ef2f20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118020ae0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118020b20>] 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 0x0000000119437c18> 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 0x0000000119f945a0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000119f945a0> 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 0x0000000150f0e8a8> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000150f0e8a8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000150f0e8a8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000150f0e8a8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015197c720> 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 0x000000012a02cde8> 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 0x10604d698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10604d678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1060517c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000138f4b9b8>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000150f0ee20>, <W_TypeObject 'GenericAlias' at 0x12a018cd0>, ...] 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 0x1393de950> 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 0x1393de950> 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 0x1393de950> 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 0x1393de950> 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 0x1047b9f70>> w_obj = <W_TypeObject 'ellipsis' at 0x1393de950> 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 0x1393de950>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1047b9f70>> 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 0x1393de950> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1047b9f70>> @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 0x1047b9f70>> 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 0x1047b9f70>> 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 0x0000000119b0de98>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001382549f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000129ef2f20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118020ae0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118020b20>] 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 0x0000000129ef2f20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118020ae0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118020b20>] 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 0x000000015254d5b0> 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 0x000000011a3e55e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000011a3e55e0> 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 0x000000011a4166e8> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000011a4166e8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000011a4166e8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000011a4166e8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000011a4aafa0> 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 0x000000011a54b4b0> 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 0x1060cd698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1060cd678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1060d17c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000138f4b9b8>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000011a416c60>, <W_TypeObject 'GenericAlias' at 0x139bb46e8>, ...] 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 0x139bf9c90> 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 0x139bf9c90> 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 0x139bf9c90> 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 0x139bf9c90> 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 0x104de1820>> w_obj = <W_TypeObject 'ellipsis' at 0x139bf9c90> 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 0x139bf9c90>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104de1820>> 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 0x139bf9c90> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104de1820>> @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 0x104de1820>> 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 0x104de1820>> 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 0x0000000139dd9088>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001382549f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000129ef2f20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118020ae0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118020b20>] 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 0x0000000129ef2f20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118020ae0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118020b20>] 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 0x000000013a5dd790> 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 0x000000012af45320> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000012af45320> 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 0x000000012af4d0c0> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000012af4d0c0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000012af4d0c0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000012af4d0c0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000148f3aba0> 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 0x000000011933d6a8> 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 0x10604d698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10604d678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1060517c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000138f4b9b8>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000012af4d638>, <W_TypeObject 'GenericAlias' at 0x129d99b08>, ...] 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 0x1394ed210> 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 0x1394ed210> 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 0x1394ed210> 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 0x1394ed210> 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 0x1047b1d50>> w_obj = <W_TypeObject 'ellipsis' at 0x1394ed210> 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 0x1394ed210>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1047b1d50>> 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 0x1394ed210> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1047b1d50>> @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 0x1047b1d50>> 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 0x1047b1d50>> 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 0x0000000150eb3f88>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001382549f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000129ef2f20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118020ae0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118020b20>] 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 0x0000000129ef2f20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118020ae0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118020b20>] 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 0x0000000151406750> 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 0x000000011a6334e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000011a6334e0> 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 0x000000011a651bb0> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000011a651bb0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000011a651bb0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000011a651bb0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000013a634ee0> 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 0x0000000148cd8950> 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 0x1060cd698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1060cd678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1060d17c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000138f4b9b8>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000017822c170>, <W_TypeObject 'GenericAlias' at 0x11a82d3d0>, ...] 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 0x11a8472f0> 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 0x11a8472f0> 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 0x11a8472f0> 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 0x11a8472f0> 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 0x104e18490>> w_obj = <W_TypeObject 'ellipsis' at 0x11a8472f0> 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 0x11a8472f0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104e18490>> 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 0x11a8472f0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104e18490>> @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 0x104e18490>> 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 0x104e18490>> 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 0x0000000139dd8e30>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001382549f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000129ef2f20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118020ae0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118020b20>] 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 0x0000000129ef2f20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000118020ae0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118020b20>] 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 0x00000001399488b8> 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 0x00000001399784e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001399784e0> 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 0x00000001399698d8> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001399698d8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001399698d8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x00000001399698d8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001399799e0> 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 0x0000000129b93130> 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 0x10604d698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10604d678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1060517c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000138f4b9b8>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000139969e50>, <W_TypeObject 'GenericAlias' at 0x150e68c28>, ...] 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 0x129db6138> 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 0x129db6138> 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 0x129db6138> 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 0x129db6138> 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 0x104d9bb70>> w_obj = <W_TypeObject 'ellipsis' at 0x129db6138> 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 0x129db6138>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104d9bb70>> 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 0x129db6138> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104d9bb70>> @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 0x104d9bb70>> 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 0x104d9bb70>> 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 32.54 seconds =========================== ++ 06:01:12 starting module/cpyext/test/test_capsule.py [87 started in total] __ module/cpyext/test/test_capsule.py [85 done in total, somefailed=True] _____ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 0x0000000150208368>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001308a49f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001117ed9a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001100b0920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001100b0960>] 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 0x00000001117ed9a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001100b0920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001100b0960>] 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 0x00000001501fd9c0> 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 0x00000001501e90a0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001501e90a0> 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 0x000000015020e368> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015020e368> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015020e368> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000015020e368> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000120fb3120> 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 0x0000000131f726b0> 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 0x104d5d698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x104d5d678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104d617c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000001581e0640>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000015020e8e0>, <W_TypeObject 'GenericAlias' at 0x111a14838>, ...] 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 0x13205c790> 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 0x13205c790> 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 0x13205c790> 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 0x13205c790> 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 0x1046a03d0>> w_obj = <W_TypeObject 'ellipsis' at 0x13205c790> 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 0x13205c790>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1046a03d0>> 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 0x13205c790> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1046a03d0>> @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 0x1046a03d0>> 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 0x1046a03d0>> 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 0x00000001494cf628>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001308a49f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001117ed9a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001100b0920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001100b0960>] 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 0x00000001117ed9a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001100b0920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001100b0960>] 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 0x0000000131a78ca0> 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 0x0000000112161360> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000112161360> 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 0x000000011178f590> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000011178f590> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000011178f590> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000011178f590> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001121a6a60> 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 0x00000001210a63d8> 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 0x10604d698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10604d678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1060517c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000001581e0640>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000011178fb08>, <W_TypeObject 'GenericAlias' at 0x131e03b78>, ...] 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 0x1117f3558> 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 0x1117f3558> 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 0x1117f3558> 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 0x1117f3558> 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 0x104f04090>> w_obj = <W_TypeObject 'ellipsis' at 0x1117f3558> 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 0x1117f3558>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104f04090>> 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 0x1117f3558> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104f04090>> @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 0x104f04090>> 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 0x104f04090>> 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 0x0000000131ef18f8>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001308a49f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001117ed9a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001100b0920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001100b0960>] 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 0x00000001117ed9a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001100b0920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001100b0960>] 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 0x0000000121ee6430> 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 0x0000000132b48120> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000132b48120> 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 0x0000000121ee2d78> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000121ee2d78> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000121ee2d78> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000121ee2d78> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000132b49aa0> 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 0x0000000132c4bda8> 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 0x1060cd698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1060cd678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1060d17c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000001581e0640>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000121ee32f0>, <W_TypeObject 'GenericAlias' at 0x1122b52b8>, ...] 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 0x14a3a3520> 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 0x14a3a3520> 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 0x14a3a3520> 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 0x14a3a3520> 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 0x104e95ac0>> w_obj = <W_TypeObject 'ellipsis' at 0x14a3a3520> 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 0x14a3a3520>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104e95ac0>> 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 0x14a3a3520> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104e95ac0>> @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 0x104e95ac0>> 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 0x104e95ac0>> 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 16.91 seconds =========================== ++ 06:01:44 starting module/cpyext/test/test_cell.py [88 started in total] __ module/cpyext/test/test_cell.py [86 done in total, somefailed=True] ________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 0x000000014aca4368>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x0000000148884a30> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000017910d960>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001182268e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118226920>] 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 0x000000017910d960>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001182268e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000118226920>] 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 0x000000014acae4d0> 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 0x000000014ac55fa0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014ac55fa0> 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 0x000000014ac9da28> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014ac9da28> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014ac9da28> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014ac9da28> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000128228ee0> 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 0x000000030824cb48> 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 0x104f61698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x104f61678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104f657c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000014a69e9f8>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014ac9dfa0>, <W_TypeObject 'GenericAlias' at 0x170f3d360>, ...] 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 0x14b02e288> 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 0x14b02e288> 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 0x14b02e288> 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 0x14b02e288> 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 0x106021ae0>> w_obj = <W_TypeObject 'ellipsis' at 0x14b02e288> 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 0x14b02e288>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x106021ae0>> 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 0x14b02e288> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x106021ae0>> @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 0x106021ae0>> 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 0x106021ae0>> 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 ============================ ++ 06:02:05 starting module/cpyext/test/test_classobject.py [89 started in total] __ module/bz2/test [87 done in total, somefailed=False] _______________________ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 286.63 seconds ==================== ++ 06:02:14 starting module/cpyext/test/test_codecs.py [90 started in total] __ module/cpyext/test/test_classobject.py [88 done in total, somefailed=True] _ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 0x0000000140bda278>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001588a49f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140acc1e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000158b10b20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000158b10b60>] 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 0x0000000140acc1e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000158b10b20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000158b10b60>] 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 0x0000000140bd67f0> 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 0x0000000140bb4ee0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000140bb4ee0> 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 0x0000000140bc9a98> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000140bc9a98> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000140bc9a98> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000140bc9a98> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000011a5a4520> 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 0x000000011a68d590> 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 0x1054c1698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1054c1678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1054c57c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000012905c800>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000140be2058>, <W_TypeObject 'GenericAlias' at 0x159d46608>, ...] 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 0x129b76678> 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 0x129b76678> 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 0x129b76678> 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 0x129b76678> 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 0x10521bc30>> w_obj = <W_TypeObject 'ellipsis' at 0x129b76678> 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 0x129b76678>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10521bc30>> 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 0x129b76678> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10521bc30>> @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 0x10521bc30>> 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 0x10521bc30>> 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 0x000000011b3a0020>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001588a49f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140acc1e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000158b10b20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000158b10b60>] 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 0x0000000140acc1e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000158b10b20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000158b10b60>] 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 0x000000011b342638> 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 0x000000011b36e320> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000011b36e320> 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 0x000000011b37a5d0> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000011b37a5d0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000011b37a5d0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000011b37a5d0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000158b68820> 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 0x00000001596c42c0> 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 0x10564d698>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10564d678>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1056517c8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000012905c800>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000011b37ab48>, <W_TypeObject 'GenericAlias' at 0x11a364678>, ...] 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 0x159a48c60> 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 0x159a48c60> 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 0x159a48c60> 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 0x159a48c60> 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 0x10512f9a0>> w_obj = <W_TypeObject 'ellipsis' at 0x159a48c60> 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 0x159a48c60>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10512f9a0>> 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 0x159a48c60> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10512f9a0>> @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 0x10512f9a0>> 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 0x10512f9a0>> 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 11.61 seconds =========================== ++ 06:02:29 starting module/cpyext/test/test_complexobject.py [91 started in total] __ module/cpyext/test/test_codecs.py [89 done in total, somefailed=True] ______ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 0x10206f140>> 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 0x100e37d20>> 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 0x0000000139c90908>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001288a6950> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000129297b60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001302897a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001302897e0>] 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 0x0000000129297b60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001302897a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001302897e0>] 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 0x0000000149cecf98> 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 0x00000001297d03e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001297d03e0> 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 0x00000001297c9018> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001297c9018> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001297c9018> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x00000001297c9018> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000150052060> 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 0x0000000150094090> 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 0x1022cd6a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1022cd688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1022d17d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000128ae72f0>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x00000001297c9590>, <W_TypeObject 'GenericAlias' at 0x149b88d08>, ...] 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 0x149bdc918> 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 0x149bdc918> 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 0x149bdc918> 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 0x149bdc918> 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 0x1020820b0>> w_obj = <W_TypeObject 'ellipsis' at 0x149bdc918> 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 0x149bdc918>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1020820b0>> 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 0x149bdc918> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1020820b0>> @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 0x1020820b0>> 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 0x1020820b0>> 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 16.48 seconds =========================== ++ 06:02:46 starting module/cpyext/test/test_contextvars.py [92 started in total] __ module/cpyext/test/test_bytesobject.py [90 done in total, somefailed=True] _ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 0x0000000139a7c368>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001202349f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001415cde60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000130670920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000130670960>] 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 0x00000001415cde60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000130670920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000130670960>] 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 0x0000000139a87380> 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 0x0000000139a817e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000139a817e0> 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 0x0000000139a88790> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000139a88790> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000139a88790> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000139a88790> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000131c65fa0> 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 0x0000000131d3d8a0> 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 0x101ac16a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x101ac1688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x101ac57d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000120a33a28>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000139a88d08>, <W_TypeObject 'GenericAlias' at 0x131dd0d78>, ...] 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 0x1418e50f8> 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 0x1418e50f8> 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 0x1418e50f8> 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 0x1418e50f8> 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 0x10875b340>> w_obj = <W_TypeObject 'ellipsis' at 0x1418e50f8> 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 0x1418e50f8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10875b340>> 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 0x1418e50f8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10875b340>> @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 0x10875b340>> 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 0x10875b340>> 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 0x0000000131a1ae30>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001202349f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001415cde60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000130670920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000130670960>] 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 0x00000001415cde60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000130670920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000130670960>] 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 0x000000014148f768> 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 0x000000014844b3e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014844b3e0> 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 0x00000001415c8e90> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001415c8e90> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001415c8e90> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x00000001415c8e90> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000131b0aca0> 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 0x0000000139cc1e88> 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 0x101b416a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x101b41688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x101b457d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000120a33a28>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x00000001415c9408>, <W_TypeObject 'GenericAlias' at 0x12140f4e8>, ...] 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 0x139866528> 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 0x139866528> 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 0x139866528> 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 0x139866528> 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 0x100e1e280>> w_obj = <W_TypeObject 'ellipsis' at 0x139866528> 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 0x139866528>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x100e1e280>> 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 0x139866528> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x100e1e280>> @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 0x100e1e280>> 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 0x100e1e280>> 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 0x0000000131c755b0>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001202349f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001415cde60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000130670920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000130670960>] 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 0x00000001415cde60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000130670920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000130670960>] 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 0x0000000132869c90> 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 0x00000001329433e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001329433e0> 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 0x0000000132974330> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000132974330> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000132974330> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000132974330> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000141e0e9e0> 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 0x00000001221d76e0> 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 0x10214d6a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10214d688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1021517d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000120a33a28>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x00000001329748a8>, <W_TypeObject 'GenericAlias' at 0x1420c5bb0>, ...] 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 0x142116ec8> 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 0x142116ec8> 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 0x142116ec8> 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 0x142116ec8> 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 0x1019a5650>> w_obj = <W_TypeObject 'ellipsis' at 0x142116ec8> 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 0x142116ec8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1019a5650>> 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 0x142116ec8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1019a5650>> @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 0x1019a5650>> 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 0x1019a5650>> 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 0x00000001421af880>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001202349f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001415cde60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000130670920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000130670960>] 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 0x00000001415cde60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000130670920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000130670960>] 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 0x000000013a962368> 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 0x000000013a966360> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000013a966360> 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 0x000000013a957280> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000013a957280> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000013a957280> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000013a957280> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000013a967ca0> 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 0x00000001483c8448> 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 0x101b416a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x101b41688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x101b457d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000120a33a28>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000013a9577f8>, <W_TypeObject 'GenericAlias' at 0x139895ec0>, ...] 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 0x131b51248> 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 0x131b51248> 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 0x131b51248> 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 0x131b51248> 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 0x100e33b50>> w_obj = <W_TypeObject 'ellipsis' at 0x131b51248> 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 0x131b51248>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x100e33b50>> 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 0x131b51248> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x100e33b50>> @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 0x100e33b50>> 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 0x100e33b50>> 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 0x0000000139a7cf20>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001202349f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001415cde60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000130670920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000130670960>] 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 0x00000001415cde60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000130670920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000130670960>] 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 0x0000000141a231c8> 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 0x00000001416729e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001416729e0> 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 0x000000014169c480> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014169c480> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014169c480> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014169c480> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015827c0e0> 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 0x0000000158277ef8> 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 0x1021cd6a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1021cd688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1021d17d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000120a33a28>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014169c9f8>, <W_TypeObject 'GenericAlias' at 0x1486bc288>, ...] 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 0x1218aa0c8> 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 0x1218aa0c8> 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 0x1218aa0c8> 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 0x1218aa0c8> 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 0x10200c890>> w_obj = <W_TypeObject 'ellipsis' at 0x1218aa0c8> 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 0x1218aa0c8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10200c890>> 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 0x1218aa0c8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10200c890>> @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 0x10200c890>> 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 0x10200c890>> 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 0x0000000121ba8728>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001202349f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001415cde60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000130670920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000130670960>] 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 0x00000001415cde60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000130670920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000130670960>] 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 0x000000013b108c00> 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 0x000000013b1118a0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000013b1118a0> 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 0x000000013b150218> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000013b150218> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000013b150218> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000013b150218> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000013b1c7760> 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 0x0000000132905948> 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 0x10234d6a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10234d688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1023517d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000120a33a28>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000013b150ad8>, <W_TypeObject 'GenericAlias' at 0x14246e218>, ...] 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 0x139eab4b0> 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 0x139eab4b0> 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 0x139eab4b0> 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 0x139eab4b0> 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 0x100ea6ca0>> w_obj = <W_TypeObject 'ellipsis' at 0x139eab4b0> 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 0x139eab4b0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x100ea6ca0>> 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 0x139eab4b0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x100ea6ca0>> @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 0x100ea6ca0>> 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 0x100ea6ca0>> 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 0x00000001486efad8>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001202349f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001415cde60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000130670920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000130670960>] 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 0x00000001415cde60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000130670920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000130670960>] 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 0x0000000131c858f8> 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 0x000000012277ed60> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000012277ed60> 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 0x000000012279ba60> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000012279ba60> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000012279ba60> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000012279ba60> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000132a8c860> 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 0x00000001422e4988> 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 0x101b416a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x101b41688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x101b457d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000120a33a28>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000132a38020>, <W_TypeObject 'GenericAlias' at 0x1422282f8>, ...] 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 0x1421ee480> 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 0x1421ee480> 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 0x1421ee480> 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 0x1421ee480> 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 0x1019dcd30>> w_obj = <W_TypeObject 'ellipsis' at 0x1421ee480> 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 0x1421ee480>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1019dcd30>> 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 0x1421ee480> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1019dcd30>> @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 0x1019dcd30>> 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 0x1019dcd30>> 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 0x0000000139afa188>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001202349f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001415cde60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000130670920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000130670960>] 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 0x00000001415cde60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000130670920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000130670960>] 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 0x0000000122248598> 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 0x0000000122266720> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000122266720> 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 0x000000012223dec0> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000012223dec0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000012223dec0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000012223dec0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000122267de0> 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 0x0000000133035248> 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 0x1023cd6a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1023cd688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1023d17d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000120a33a28>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000132d98480>, <W_TypeObject 'GenericAlias' at 0x141477a60>, ...] 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 0x1316ba870> 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 0x1316ba870> 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 0x1316ba870> 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 0x1316ba870> 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 0x100c9dbc0>> w_obj = <W_TypeObject 'ellipsis' at 0x1316ba870> 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 0x1316ba870>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x100c9dbc0>> 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 0x1316ba870> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x100c9dbc0>> @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 0x100c9dbc0>> 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 0x100c9dbc0>> 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 0x000000013004d538>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001202349f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001415cde60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000130670920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000130670960>] 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 0x00000001415cde60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000130670920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000130670960>] 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 0x000000014172b588> 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 0x0000000139ef64e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000139ef64e0> 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 0x0000000139ee85d0> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000139ee85d0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000139ee85d0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000139ee85d0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000139ef7be0> 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 0x0000000141e14058> 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 0x101b416a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x101b41688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x101b457d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000120a33a28>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000139ee8b48>, <W_TypeObject 'GenericAlias' at 0x141972ad8>, ...] 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 0x122d3cd08> 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 0x122d3cd08> 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 0x122d3cd08> 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 0x122d3cd08> 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 0x100d369e0>> w_obj = <W_TypeObject 'ellipsis' at 0x122d3cd08> 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 0x122d3cd08>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x100d369e0>> 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 0x122d3cd08> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x100d369e0>> @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 0x100d369e0>> 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 0x100d369e0>> 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 0x100b86720>> 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 0x1019dbb60>> 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 0x102238b20>> 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 0x1018f05d0>> 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 0x102064b50>> 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 0x100eac490>> 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 0x101969200>> 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 0x10205aad0>> 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 0x10214df40>> 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 0x102165c20>> 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 0x102005ae0>> 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 103.05 seconds ========================== ++ 06:02:54 starting module/cpyext/test/test_cpyext.py [93 started in total] __ module/cpyext/test/test_contextvars.py [91 done in total, somefailed=True] _ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 0x000000012953acc8>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001488a49f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001294925e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000012811e920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000012811e960>] 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 0x00000001294925e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000012811e920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000012811e960>] 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 0x000000012952b8d0> 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 0x000000012951dea0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000012951dea0> 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 0x0000000129529d70> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000129529d70> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000129529d70> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000129529d70> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001295a6920> 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 0x0000000118441718> 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 0x1050216a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x105021688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1050257d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000001294269f8>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000149f52330>, <W_TypeObject 'GenericAlias' at 0x14a04a480>, ...] 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 0x1296641e0> 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 0x1296641e0> 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 0x1296641e0> 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 0x1296641e0> 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 0x1053b7e70>> w_obj = <W_TypeObject 'ellipsis' at 0x1296641e0> 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 0x1296641e0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1053b7e70>> 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 0x1296641e0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1053b7e70>> @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 0x1053b7e70>> 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 0x1053b7e70>> 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.08 seconds ============================ ++ 06:03:07 starting module/cpyext/test/test_datetime.py [94 started in total] __ module/cpyext/test/test_complexobject.py [92 done in total, somefailed=True] ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 0x10554ed40>> 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 0x0000000151e25268>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001208a49f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001103834e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001282e0ae0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001282e0b20>] 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 0x00000001103834e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001282e0ae0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001282e0b20>] 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 0x0000000139f08e08> 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 0x0000000139efda20> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000139efda20> 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 0x0000000139f3cb80> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000139f3cb80> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000139f3cb80> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000139f3cb80> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000128283f60> 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 0x0000000138f334e8> 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 0x1057416a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x105741688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1057457d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000129822c98>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000139f3d0f8>, <W_TypeObject 'GenericAlias' at 0x1218efbe8>, ...] 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 0x129f78560> 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 0x129f78560> 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 0x129f78560> 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 0x129f78560> 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 0x104ccf530>> w_obj = <W_TypeObject 'ellipsis' at 0x129f78560> 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 0x129f78560>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104ccf530>> 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 0x129f78560> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104ccf530>> @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 0x104ccf530>> 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 0x104ccf530>> 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 0x00000001519822f0>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001208a49f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001103834e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001282e0ae0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001282e0b20>] 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 0x00000001103834e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001282e0ae0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001282e0b20>] 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 0x0000000121bbd740> 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 0x00000001223b3d60> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001223b3d60> 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 0x00000001223f88e0> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001223f88e0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001223f88e0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x00000001223f88e0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000012a6696a0> 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 0x00000001224a7c58> 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 0x1057c16a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1057c1688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1057c57d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000129822c98>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x00000001223f8e58>, <W_TypeObject 'GenericAlias' at 0x1301eff30>, ...] 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 0x12a6bd868> 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 0x12a6bd868> 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 0x12a6bd868> 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 0x12a6bd868> 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 0x11d7430f0>> w_obj = <W_TypeObject 'ellipsis' at 0x12a6bd868> 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 0x12a6bd868>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11d7430f0>> 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 0x12a6bd868> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11d7430f0>> @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 0x11d7430f0>> 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 0x11d7430f0>> 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 0x000000012ade15b0>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001208a49f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001103834e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001282e0ae0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001282e0b20>] 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 0x00000001103834e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001282e0ae0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001282e0b20>] 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 0x0000000122d89830> 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 0x00000001535cf2e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001535cf2e0> 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 0x00000001535d4608> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001535d4608> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001535d4608> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x00000001535d4608> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000122e429e0> 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 0x000000012ae9bad0> 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 0x10684d6a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10684d688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1068517d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000129822c98>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x00000001535d4b80>, <W_TypeObject 'GenericAlias' at 0x122f3c6b0>, ...] 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 0x122f77de0> 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 0x122f77de0> 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 0x122f77de0> 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 0x122f77de0> 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 0x104cd17f0>> w_obj = <W_TypeObject 'ellipsis' at 0x122f77de0> 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 0x122f77de0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104cd17f0>> 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 0x122f77de0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x104cd17f0>> @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 0x104cd17f0>> 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 0x104cd17f0>> 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 0x0000000140463358>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001208a49f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001103834e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001282e0ae0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001282e0b20>] 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 0x00000001103834e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001282e0ae0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001282e0b20>] 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 0x00000001515db380> 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 0x0000000151e23d60> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000151e23d60> 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 0x00000001534896e0> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001534896e0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001534896e0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x00000001534896e0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001225f9320> 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 0x0000000139d78608> 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 0x1057416a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x105741688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1057457d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000129822c98>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000153489c58>, <W_TypeObject 'GenericAlias' at 0x1396bd050>, ...] 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 0x1396bf0f8> 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 0x1396bf0f8> 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 0x1396bf0f8> 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 0x1396bf0f8> 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 0x105434ea0>> w_obj = <W_TypeObject 'ellipsis' at 0x1396bf0f8> 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 0x1396bf0f8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x105434ea0>> 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 0x1396bf0f8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x105434ea0>> @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 0x105434ea0>> 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 0x105434ea0>> 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 0x0000000139bc0548>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001208a49f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001103834e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001282e0ae0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001282e0b20>] 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 0x00000001103834e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000001282e0ae0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000001282e0b20>] 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 0x00000001228abb78> 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 0x0000000122998e60> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000122998e60> 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 0x00000001229a3280> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001229a3280> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001229a3280> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x00000001229a3280> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001533e88a0> 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 0x000000013023fa28> 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 0x1057c16a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1057c1688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1057c57d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000129822c98>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x00000001229a37f8>, <W_TypeObject 'GenericAlias' at 0x13998b1a0>, ...] 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 0x1399daad8> 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 0x1399daad8> 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 0x1399daad8> 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 0x1399daad8> 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 0x10559f7f0>> w_obj = <W_TypeObject 'ellipsis' at 0x1399daad8> 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 0x1399daad8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10559f7f0>> 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 0x1399daad8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10559f7f0>> @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 0x10559f7f0>> 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 0x10559f7f0>> 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 31.35 seconds =========================== ++ 06:03:13 starting module/cpyext/test/test_dictobject.py [95 started in total] __ module/cpyext/test/test_datetime.py [93 done in total, somefailed=True] ____ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 0x133e67fa0>> 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 0x1012308b0>> 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 0x1028b8180>> 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 0x133e81dc0>> 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 0x102a5a760>> 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 0x113e23700>> 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 0x1011966e0>> 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 0x10285cdd0>> 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 0x102960240>> 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 0x000000010b3756a0>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001282549c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000015170b860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140067620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140067660>] 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 0x000000015170b860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140067620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140067660>] 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 0x000000010919fd08> 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 0x000000014276f960> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000014276f960> 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 0x0000000142bee4b8> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000142bee4b8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000142bee4b8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000142bee4b8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000142c0b7e0> 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 0x00000001428dca68> 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 0x102b4d6a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x102b4d688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102b517d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000128afb9b8>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000142beea30>, <W_TypeObject 'GenericAlias' at 0x141ce0640>, ...] 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 0x141d17d38> 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 0x141d17d38> 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 0x141d17d38> 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 0x141d17d38> 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 0x1029855e0>> w_obj = <W_TypeObject 'ellipsis' at 0x141d17d38> 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 0x141d17d38>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1029855e0>> 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 0x141d17d38> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1029855e0>> @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 0x1029855e0>> 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 0x1029855e0>> 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 0x0000000151775088>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001282549c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000015170b860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140067620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140067660>] 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 0x000000015170b860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140067620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140067660>] 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 0x000000010a107650> 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 0x000000010acc89a0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000010acc89a0> 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 0x000000010ac8b398> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000010ac8b398> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000010ac8b398> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000010ac8b398> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000109ee41e0> 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 0x0000000109ec3ad0> 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 0x102c4d6a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x102c4d688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102c517d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000128afb9b8>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000010ac8b910>, <W_TypeObject 'GenericAlias' at 0x12a238bb8>, ...] 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 0x1424dc1e0> 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 0x1424dc1e0> 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 0x1424dc1e0> 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 0x1424dc1e0> 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 0x1012b1710>> w_obj = <W_TypeObject 'ellipsis' at 0x1424dc1e0> 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 0x1424dc1e0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1012b1710>> 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 0x1424dc1e0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1012b1710>> @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 0x1012b1710>> 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 0x1012b1710>> 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 0x00000001431a0098>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001282549c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000015170b860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140067620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140067660>] 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 0x000000015170b860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140067620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140067660>] 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 0x000000012ac6a958> 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 0x0000000143199260> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000143199260> 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 0x000000012ac754e8> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000012ac754e8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000012ac754e8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000012ac754e8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000010b3bcae0> 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 0x00000001512342f8> 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 0x102b4d6a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x102b4d688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102b517d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000128afb9b8>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000012ac75a60>, <W_TypeObject 'GenericAlias' at 0x150afc5d0>, ...] 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 0x141cd59b8> 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 0x141cd59b8> 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 0x141cd59b8> 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 0x141cd59b8> 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 0x102d0b140>> w_obj = <W_TypeObject 'ellipsis' at 0x141cd59b8> 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 0x141cd59b8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102d0b140>> 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 0x141cd59b8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102d0b140>> @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 0x102d0b140>> 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 0x102d0b140>> 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 0x0000000129129d30>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001282549c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000015170b860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140067620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140067660>] 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 0x000000015170b860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140067620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140067660>] 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 0x0000000151a1a638> 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 0x00000001428d6a20> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001428d6a20> 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 0x0000000151a6d638> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000151a6d638> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000151a6d638> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000151a6d638> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000012998e0a0> 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 0x0000000141fdd750> 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 0x102bcd6a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x102bcd688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102bd17d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000128afb9b8>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000151a6dbb0>, <W_TypeObject 'GenericAlias' at 0x151e50790>, ...] 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 0x1519b3cc8> 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 0x1519b3cc8> 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 0x1519b3cc8> 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 0x1519b3cc8> 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 0x102d40a10>> w_obj = <W_TypeObject 'ellipsis' at 0x1519b3cc8> 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 0x1519b3cc8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102d40a10>> 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 0x1519b3cc8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102d40a10>> @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 0x102d40a10>> 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 0x102d40a10>> 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 0x00000001299349f8>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001282549c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000015170b860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140067620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140067660>] 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 0x000000015170b860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140067620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140067660>] 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 0x000000010a403d30> 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 0x0000000109f82f20> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000109f82f20> 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 0x0000000109fcadb0> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000109fcadb0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000109fcadb0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000109fcadb0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000010a6c0660> 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 0x0000000129abb4e8> 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 0x102ccd6a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x102ccd688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102cd17d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000128afb9b8>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000109fcb328>, <W_TypeObject 'GenericAlias' at 0x151dec330>, ...] 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 0x151e15cc8> 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 0x151e15cc8> 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 0x151e15cc8> 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 0x151e15cc8> 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 0x102d75790>> w_obj = <W_TypeObject 'ellipsis' at 0x151e15cc8> 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 0x151e15cc8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102d75790>> 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 0x151e15cc8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102d75790>> @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 0x102d75790>> 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 0x102d75790>> 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 0x00000001431a1d30>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001282549c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000015170b860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140067620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140067660>] 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 0x000000015170b860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140067620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140067660>] 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 0x0000000109297f10> 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 0x0000000129dbdba0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000129dbdba0> 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 0x000000010998fd38> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000010998fd38> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000010998fd38> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000010998fd38> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000129d2d720> 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 0x00000001480f7788> 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 0x102b4d6a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x102b4d688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102b517d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000128afb9b8>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x00000001099762f8>, <W_TypeObject 'GenericAlias' at 0x1519ad520>, ...] 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 0x151942ec8> 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 0x151942ec8> 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 0x151942ec8> 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 0x151942ec8> 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 0x102ab3800>> w_obj = <W_TypeObject 'ellipsis' at 0x151942ec8> 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 0x151942ec8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102ab3800>> 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 0x151942ec8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102ab3800>> @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 0x102ab3800>> 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 0x102ab3800>> 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 0x0000000151756ae8>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001282549c0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000015170b860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140067620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140067660>] 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 0x000000015170b860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000140067620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000140067660>] 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 0x000000012a5f67f0> 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 0x000000010a9489e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000010a9489e0> 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 0x000000010a9370f8> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000010a9370f8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000010a9370f8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000010a9370f8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001582f6160> 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 0x000000010a70e790> 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 0x102bcd6a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x102bcd688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102bd17d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000128afb9b8>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000010a937670>, <W_TypeObject 'GenericAlias' at 0x1528f0d08>, ...] 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 0x152270b10> 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 0x152270b10> 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 0x152270b10> 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 0x152270b10> 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 0x102968c20>> w_obj = <W_TypeObject 'ellipsis' at 0x152270b10> 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 0x152270b10>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102968c20>> 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 0x152270b10> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x102968c20>> @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 0x102968c20>> 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 0x102968c20>> 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 82.65 seconds =========================== ++ 06:04:49 starting module/cpyext/test/test_eval.py [96 started in total] __ module/cpyext/test/test_dictobject.py [94 done in total, somefailed=True] __ ============================= test session starts ============================== platform darwin -- Python 2.7.18[pypy-7.3.17-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/Users/matti/build-worker-arm64/own-macos-arm64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /Users/matti/build-worker-arm64/own-macos-arm64/build/pytest.pyc rootdir: /Users/matti/build-worker-arm64/own-macos-arm64/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 0x101c207f0>> 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 0x1010f62e0>> 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 0x101d73e10>> 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 0x101b77030>> 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 0x101b13990>> 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 0x101ace980>> 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 0x101a4edd0>> 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 0x101b4cfc0>> 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 0x00000001590b2548>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001307649f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000111b946a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000110226920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000110226960>] 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 0x0000000111b946a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000110226920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000110226960>] 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 0x00000001595ec5c0> 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 0x00000001595b91e0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000001595b91e0> 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 0x000000010891e020> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000010891e020> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000010891e020> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000010891e020> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x00000001323e2c60> 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 0x000000014041e2c0> 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 0x101ecd6a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x101ecd688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x101ed17d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000001114a3360>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000010891e598>, <W_TypeObject 'GenericAlias' at 0x132d9ec28>, ...] 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 0x132db6e58> 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 0x132db6e58> 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 0x132db6e58> 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 0x132db6e58> 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 0x101aea4d0>> w_obj = <W_TypeObject 'ellipsis' at 0x132db6e58> 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 0x132db6e58>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x101aea4d0>> 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 0x132db6e58> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x101aea4d0>> @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 0x101aea4d0>> 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 0x101aea4d0>> 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 0x0000000120742908>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001307649f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000111b946a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000110226920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000110226960>] 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 0x0000000111b946a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000110226920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000110226960>] 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 0x00000001118e5e48> 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 0x0000000131a26360> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000131a26360> 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 0x000000014982d2f0> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014982d2f0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000014982d2f0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000014982d2f0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000131a27b20> 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 0x0000000149c61750> 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 0x101e4d6a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x101e4d688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x101e517d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000001114a3360>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000014982d8a0>, <W_TypeObject 'GenericAlias' at 0x1311d12b8>, ...] 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 0x111aa48e0> 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 0x111aa48e0> 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 0x111aa48e0> 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 0x111aa48e0> 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 0x101daddb0>> w_obj = <W_TypeObject 'ellipsis' at 0x111aa48e0> 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 0x111aa48e0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x101daddb0>> 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 0x111aa48e0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x101daddb0>> @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 0x101daddb0>> 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 0x101daddb0>> 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 0x0000000158cf6188>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001307649f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000111b946a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000110226920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000110226960>] 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 0x0000000111b946a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000110226920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000110226960>] 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 0x0000000131ec9560> 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 0x0000000112904520> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000112904520> 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 0x0000000159c94020> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000159c94020> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x0000000159c94020> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x0000000159c94020> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000112905d60> 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 0x00000001121c0bf0> 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 0x101f4d6a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x101f4d688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x101f517d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000001114a3360>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x0000000159c94598>, <W_TypeObject 'GenericAlias' at 0x1326c8c98>, ...] 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 0x149914b10> 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 0x149914b10> 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 0x149914b10> 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 0x149914b10> 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 0x101bc9780>> w_obj = <W_TypeObject 'ellipsis' at 0x149914b10> 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 0x149914b10>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x101bc9780>> 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 0x149914b10> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x101bc9780>> @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 0x101bc9780>> 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 0x101bc9780>> 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 0x000000015a570110>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001307649f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000111b946a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000110226920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000110226960>] 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 0x0000000111b946a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000110226920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000110226960>] 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 0x000000015a625830> 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 0x000000015a6bdce0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000015a6bdce0> 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 0x000000015a6f1b08> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015a6f1b08> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000015a6f1b08> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000015a6f1b08> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000015a7775a0> 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 0x000000013398ef70> 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 0x101fcd6a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x101fcd688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x101fd17d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000001114a3360>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000015a7680c8>, <W_TypeObject 'GenericAlias' at 0x1118d4ad8>, ...] 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 0x11196c3d8> 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 0x11196c3d8> 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 0x11196c3d8> 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 0x11196c3d8> 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 0x101d18d70>> w_obj = <W_TypeObject 'ellipsis' at 0x11196c3d8> 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 0x11196c3d8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x101d18d70>> 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 0x11196c3d8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x101d18d70>> @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 0x101d18d70>> 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 0x101d18d70>> 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 0x000000014a58f088>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001307649f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000111b946a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000110226920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000110226960>] 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 0x0000000111b946a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000110226920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000110226960>] 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 0x0000000149a3ad18> 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 0x000000012065d660> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000012065d660> 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 0x000000012069a3d8> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000012069a3d8> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x000000012069a3d8> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x000000012069a3d8> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x0000000149947220> 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 0x0000000159d39718> 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 0x101e4d6a8>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x101e4d688>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x101e517d8>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000001114a3360>, W_BoolObject(True), W_BoolObject(False), <p...>, <pypy.interpreter.special.Ellipsis object at 0x000000012069a950>, <W_TypeObject 'GenericAlias' at 0x132222170>, ...] 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 0x1332131d8> 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 0x1332131d8> 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 0x1332131d8> 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 0x1332131d8> 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 0x101c28340>> w_obj = <W_TypeObject 'ellipsis' at 0x1332131d8> 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 0x1332131d8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x101c28340>> 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 0x1332131d8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x101c28340>> @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 0x101c28340>> 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 0x101c28340>> 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 0x00000001319e5100>, when = 'setup' def __init__(self, func, when): #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" self.when = when self.start = time() try: > self.result = func() ../_pytest/runner.py:150: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > return CallInfo(lambda: ihook(item=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 0x00000001307649f8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000111b946a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000110226920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000110226960>] 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 0x0000000111b946a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000110226920>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000110226960>] 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 0x0000000112a7de48> 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 0x0000000131f33ce0> def get_result(self): if self.excinfo is None: return self.result else: ex = self.excinfo if _py3: raise ex[1].with_traceback(ex[2]) > _reraise(*ex) # noqa ../_pytest/vendored_packages/pluggy.py:279: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000131f33ce0> 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 0x00000001320822c0> key = (((True, True, True, True, True, True, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...)) def gettestobjspace(**kwds): """ helper for instantiating and caching spaces for testing. """ try: config = make_config(option, **kwds) except ConflictConfigError as e: # this exception is typically only raised if a module is not available. # in this case the test should be skipped py.test.skip(str(e)) if getattr(option, 'runappdirect', None): return TinyObjSpace() key = config.getkey() try: return _SPACECACHE[key] except KeyError: > space = maketestobjspace(config) tool/pytest/objspace.py:24: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001320822c0> def maketestobjspace(config=None): if config is None: config = make_config(option) if config.objspace.usemodules.thread: config.translation.thread = True config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest' > space = make_objspace(config) tool/pytest/objspace.py:34: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ config = <rpython.config.config.Config object at 0x00000001320822c0> def make_objspace(config): from pypy.objspace.std.objspace import StdObjSpace > return StdObjSpace(config) tool/option.py:33: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace config = <rpython.config.config.Config object at 0x00000001320822c0> @not_rpython def __init__(self, config=None): "Basic initialization of objects." self.w_default_importlib_import = None self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.reverse_debugging = config.translation.reverse_debugger self.builtin_modules = {} self.reloading_modules = {} self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module make_finalizer_queue(W_Root, self) 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 0x000000013375b560> 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) 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=4227.176659