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-x86_64/own-macos-x86-64/build (timeout 4000 secs)
watching logfiles {'pytestLog': 'testrun.log'}
argv: ['virt_test/bin/python', 'testrunner/runner.py', '--logfile=testrun.log', '--config=pypy/testrunner_cfg.py', '--config=~/machine_cfg.py', '--root=pypy', '--timeout=4000']
environment:
HOME=/Users/matti
HOMEBREW_CELLAR=/opt/homebrew_x86_64/Cellar
HOMEBREW_PREFIX=/opt/homebrew_x86_64
HOMEBREW_REPOSITORY=/opt/homebrew_x86_64
INFOPATH=/opt/homebrew_x86_64/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-x86_64-buildbot/bin:/opt/homebrew_x86_64/bin:/opt/homebrew_x86_64/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_x86_64/opt/openssl@1.1/lib/pkgconfig
PWD=/Users/matti/build-worker-x86_64/own-macos-x86-64/build
PYPYCHERRYPICK=
PYPY_USESSION_DIR=/tmp/buildbot-x86_64
PYTHONPATH=.:
SHELL=/bin/zsh
SHLVL=2
SSH_CLIENT=10.0.0.17 59930 22
SSH_CONNECTION=10.0.0.17 59930 10.0.0.16 22
SSH_TTY=/dev/ttys000
TERM=xterm-256color
TMPDIR=/tmp/buildbot-x86_64/pytest
USER=matti
_=/Users/matti/oss/pypy-x86_64-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:19 starting config/test [1 started in total]
++ 05:30:19 starting interpreter/astcompiler/test [2 started in total]
++ 05:30:19 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 162 items / 1 skipped
config/test/test_pypyoption.py ..................................................................................................................................................................
==================== 162 passed, 1 skipped in 34.84 seconds ====================
++ 05:30:58 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 243 items
interpreter/pyparser/test/apptest_parsestring.py ......
interpreter/pyparser/test/test_automata.py ...
interpreter/pyparser/test/test_future.py ...................................
interpreter/pyparser/test/test_gendfa.py ....
interpreter/pyparser/test/test_parsestring.py ............
interpreter/pyparser/test/test_pylexer.py .
interpreter/pyparser/test/test_pyparse.py .................................................................................................................
interpreter/pyparser/test/test_pytokenizer.py .....................................................................
========================= 243 passed in 106.38 seconds =========================
++ 05:32:09 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 324 items
module/__builtin__/test/apptest_compile.py .....................
module/__builtin__/test/apptest_descriptor.py .......
module/__builtin__/test/apptest_operator.py .....
module/__builtin__/test/apptest_print.py ...
module/__builtin__/test/test_abstractinst.py ..........s..
module/__builtin__/test/test_breakpoint.py ........
module/__builtin__/test/test_builtin.py ........................................................................
module/__builtin__/test/test_compile.py ..
module/__builtin__/test/test_construct_singletons.py .
module/__builtin__/test/test_descriptor.py ...................................
module/__builtin__/test/test_dir.py ...........
module/__builtin__/test/test_filter.py ........
module/__builtin__/test/test_filter_pickle.py .....
module/__builtin__/test/test_format.py .
module/__builtin__/test/test_functional.py ........................................................................................
module/__builtin__/test/test_map_pickle.py ...
module/__builtin__/test/test_minmax.py .......................
module/__builtin__/test/test_rawinput.py ..
module/__builtin__/test/test_sum.py .
module/__builtin__/test/test_vars.py ...
module/__builtin__/test/test_zip.py ...........
module/__builtin__/test/test_zip_pickle.py .
==================== 323 passed, 1 skipped in 94.64 seconds ====================
++ 05:33:50 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.py
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 1566 items
interpreter/astcompiler/test/apptest_compiler.py ....................
interpreter/astcompiler/test/apptest_exceptiongroup.py .........................
interpreter/astcompiler/test/apptest_fstring.py ...............................
interpreter/astcompiler/test/apptest_misc.py .................
interpreter/astcompiler/test/apptest_patma.py .........................................
interpreter/astcompiler/test/apptest_walrus_comprehension.py ......
interpreter/astcompiler/test/test_assemble.py .......................
interpreter/astcompiler/test/test_ast.py ............
interpreter/astcompiler/test/test_astbuilder.py .................................................................................................................
interpreter/astcompiler/test/test_compiler.py .........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
interpreter/astcompiler/test/test_misc.py ...............
interpreter/astcompiler/test/test_symtable.py .................................................
interpreter/astcompiler/test/test_unparse.py ................................
interpreter/astcompiler/test/test_validate.py .....................................................
======================== 1566 passed in 211.03 seconds =========================
++ 05:33:57 starting module/_abc/test [7 started in total]
__ module/_abc/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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 6 items
module/_abc/test/apptest_abc.py ...
module/_abc/test/test_abc.py ...
========================== 6 passed in 37.60 seconds ===========================
++ 05:34:41 starting module/_ast/test [8 started in total]
__ module/__pypy__/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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 83 items
module/__pypy__/test/apptest_picklebuffer.py ........
module/__pypy__/test/test_builders.py .....
module/__pypy__/test/test_bytebuffer.py ...
module/__pypy__/test/test_debug.py .......
module/__pypy__/test/test_identitydict.py ......
module/__pypy__/test/test_intop.py ...........
module/__pypy__/test/test_locals2fast.py .....
module/__pypy__/test/test_magic.py .......s..
module/__pypy__/test/test_newmemoryview.py ........
module/__pypy__/test/test_os.py .
module/__pypy__/test/test_signal.py ..s.s
module/__pypy__/test/test_special.py ............s.
==================== 79 passed, 4 skipped in 70.76 seconds =====================
++ 05:35:03 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 57 items
module/_ast/test/apptest_ast.py ...
module/_ast/test/test_ast.py ......................................................
========================== 57 passed in 85.62 seconds ==========================
++ 05:36:08 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 99 items
module/_codecs/test/apptest_codecs.py ..
module/_codecs/test/test_codecs.py .....................sss...........................................................s......
module/_codecs/test/test_locale.py ...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 0x00007f8a5aa9e090>
locale_decoder = <function str_decode_locale_surrogateescape at 0x00007f8a58de9628>
@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 0x00007f8a5ac45398>
locale_decoder = <function str_decode_locale_strict at 0x00007f8a58de9970>
@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 137.52 seconds ===============
++ 05:38:33 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 66 items
module/_collections/test/apptest_defaultdict.py ..............
module/_collections/test/apptest_deque.py ..........................................
module/_collections/test/apptest_ordereddict.py ..........
========================== 66 passed in 65.16 seconds ==========================
++ 05:39:46 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 72 items / 2 skipped
module/_continuation/test/test_generator.py ssss
module/_continuation/test/test_greenlet.py s.ssssss.sssssssssssssss.sss
module/_continuation/test/test_stacklet.py ssssssssssssssssssssssssssssssssssssssss
==================== 3 passed, 71 skipped in 63.60 seconds =====================
++ 05:40:52 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 0 items
========================= no tests ran in 0.01 seconds =========================
++ 05:40:55 starting module/_csv/test [14 started in total]
__ module/_csv/test [12 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 34 items
module/_csv/test/apptest_writer.py ......
module/_csv/test/test_dialect.py ..............
module/_csv/test/test_reader.py .............
module/_csv/test/test_ztranslation.py .
========================== 34 passed in 63.99 seconds ==========================
++ 05:42:00 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 3 items
module/_demo/test/test_import.py ..
module/_demo/test/test_sieve.py .
========================== 3 passed in 24.94 seconds ===========================
++ 05:42:28 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-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:42:31 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-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:42:33 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-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:42:36 starting module/_hpy_universal/test/_vendored/test_capsule.py [19 started in total]
__ module/_hpy_universal/test/_vendored/test_capsule.py [17 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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_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-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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_contextvar.py [19 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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_cpy_compat.py [22 started in total]
__ module/_hpy_universal/test/_vendored/test_cpy_compat.py [20 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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_eval.py [23 started in total]
__ module/_hpy_universal/test/_vendored/test_eval.py [21 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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_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-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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_helpers.py [25 started in total]
__ module/_hpy_universal/test/_vendored/test_helpers.py [23 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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_hpybuildvalue.py [26 started in total]
__ module/_hpy_universal/test/_vendored/test_hpybuildvalue.py [24 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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_hpybytes.py [27 started in total]
__ module/_hpy_universal/test/_vendored/test_hpybytes.py [25 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:42:59 starting module/_hpy_universal/test/_vendored/test_hpydict.py [28 started in total]
__ module/_hpy_universal/test/_vendored/test_hpydict.py [26 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:43:01 starting module/_hpy_universal/test/_vendored/test_hpyerr.py [29 started in total]
__ module/_hpy_universal/test/_vendored/test_hpyerr.py [27 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:43:04 starting module/_hpy_universal/test/_vendored/test_hpyfield.py [30 started in total]
__ module/_hpy_universal/test/_vendored/test_hpyfield.py [28 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:43:06 starting module/_hpy_universal/test/_vendored/test_hpyglobal.py [31 started in total]
__ module/_hpy_universal/test/_vendored/test_hpyglobal.py [29 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:43:09 starting module/_hpy_universal/test/_vendored/test_hpyimport.py [32 started in total]
__ module/_hpy_universal/test/_vendored/test_hpyimport.py [30 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:43:12 starting module/_hpy_universal/test/_vendored/test_hpyiter.py [33 started in total]
__ module/_hpy_universal/test/_vendored/test_hpyiter.py [31 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:43:14 starting module/_hpy_universal/test/_vendored/test_hpylist.py [34 started in total]
__ module/_hpy_universal/test/_vendored/test_hpylist.py [32 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:43:17 starting module/_hpy_universal/test/_vendored/test_hpylong.py [35 started in total]
__ module/_hpy_universal/test/_vendored/test_hpylong.py [33 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:43:19 starting module/_hpy_universal/test/_vendored/test_hpymodule.py [36 started in total]
__ module/_hpy_universal/test/_vendored/test_hpymodule.py [34 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:43:22 starting module/_hpy_universal/test/_vendored/test_hpyslice.py [37 started in total]
__ module/_hpy_universal/test/_vendored/test_hpyslice.py [35 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:43:24 starting module/_hpy_universal/test/_vendored/test_hpystructseq.py [38 started in total]
__ module/_hpy_universal/test/_vendored/test_hpystructseq.py [36 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:43:27 starting module/_hpy_universal/test/_vendored/test_hpytuple.py [39 started in total]
__ module/_hpy_universal/test/_vendored/test_hpytuple.py [37 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:43:29 starting module/_hpy_universal/test/_vendored/test_hpytype.py [40 started in total]
__ module/_hpy_universal/test/_vendored/test_hpytype.py [38 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:43:32 starting module/_hpy_universal/test/_vendored/test_hpytype_legacy.py [41 started in total]
__ module/_hpy_universal/test/_vendored/test_hpytype_legacy.py [39 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:43:34 starting module/_hpy_universal/test/_vendored/test_hpyunicode.py [42 started in total]
__ module/_hpy_universal/test/_vendored/test_hpyunicode.py [40 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:43:37 starting module/_hpy_universal/test/_vendored/test_importing.py [43 started in total]
__ module/_hpy_universal/test/_vendored/test_importing.py [41 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:43:40 starting module/_hpy_universal/test/_vendored/test_legacy_forbidden.py [44 started in total]
__ module/_hpy_universal/test/_vendored/test_legacy_forbidden.py [42 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:43:42 starting module/_hpy_universal/test/_vendored/test_number.py [45 started in total]
__ module/_hpy_universal/test/_vendored/test_number.py [43 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:43:45 starting module/_hpy_universal/test/_vendored/test_object.py [46 started in total]
__ module/_hpy_universal/test/_vendored/test_object.py [44 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:43:47 starting module/_hpy_universal/test/_vendored/test_slots.py [47 started in total]
__ module/_hpy_universal/test/_vendored/test_slots.py [45 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:43:50 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-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:43:52 starting module/_hpy_universal/test/_vendored/test_support.py [49 started in total]
__ module/_hpy_universal/test/_vendored/test_support.py [47 done in total, somefailed=True]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:43:55 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-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:43:57 starting module/_hpy_universal/test/pypy [51 started in total]
__ module/_hpy_universal/test/pypy [49 done in total, somefailed=True] ________
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 05:44:01 starting module/_io/test [52 started in total]
__ interpreter/test [50 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
PYTHON3: /opt/homebrew_x86_64/bin/python3.12
(Version 3.12.6 (main, Sep 6 2024, 19:03:47) [Clang 15.0.0 (clang-1500.3.9.4)])
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 1389 items
interpreter/test/apptest_annotations.py ..........................
interpreter/test/apptest_annotations_string.py ......
interpreter/test/apptest_buffer.py .......
interpreter/test/apptest_class.py ................
interpreter/test/apptest_compiler.py ....................................................................................................
interpreter/test/apptest_coroutine.py ..........................................................
interpreter/test/apptest_descrtypecheck.py ..
interpreter/test/apptest_exceptions.py ..........................
interpreter/test/apptest_exctable_dis.py .........
interpreter/test/apptest_exec.py .........................
interpreter/test/apptest_extcall.py .....
interpreter/test/apptest_function.py .....................................s.......................................................
interpreter/test/apptest_generator.py ...................................................................
interpreter/test/apptest_nestedscope.py ..................
interpreter/test/apptest_pep695.py ...............................
interpreter/test/apptest_pycode.py ....
interpreter/test/apptest_pyframe.py ................................................................
interpreter/test/apptest_raise.py ......................................................
interpreter/test/apptest_settrace_jump.py .
interpreter/test/apptest_syntax.py ....................................
interpreter/test/apptest_sys_settrace.py ..............................................................................................................................................
interpreter/test/apptest_traceback.py ........
interpreter/test/apptest_unraisable.py ....
interpreter/test/apptest_with_leak.py .........
interpreter/test/test_app_main.py ..................s..s....................s...s.......................s....X.s...s..........
interpreter/test/test_appinterp.py .............
interpreter/test/test_argument.py ................................................
interpreter/test/test_buffer.py ...
interpreter/test/test_cellfamily.py .......
interpreter/test/test_code.py ............
interpreter/test/test_compiler.py .........
interpreter/test/test_error.py ..............
interpreter/test/test_exceptcomp.py .........
interpreter/test/test_executioncontext.py ................
interpreter/test/test_extmodules.py .
interpreter/test/test_fsencode.py 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 0x00007f9f9315f0a0>
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-x86_64/own-macos-x86-64/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-x86_64/own-macos-x86-64/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 791.68 seconds ========
++ 05:44:11 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 1 items
module/_jitlog/test/test__jitlog.py .
========================== 1 passed in 30.62 seconds ===========================
++ 05:44:44 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 15 items
module/_locale/test/test_locale.py ssssssssssssss.
==================== 1 passed, 14 skipped in 33.17 seconds =====================
++ 05:45:22 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 6 items
module/_lsprof/test/test_cprofile.py ......
========================== 6 passed in 21.65 seconds ===========================
++ 05:45:46 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 8 items
module/_md5/test/test_md5.py ........
========================== 8 passed in 17.71 seconds ===========================
++ 05:46:06 starting module/_minimal_curses/test [57 started in total]
__ module/_io/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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 287 items / 1 skipped
module/_io/test/apptest_bufferedio.py .
module/_io/test/apptest_bytesio.py .................
module/_io/test/apptest_io.py ...........................................
module/_io/test/apptest_stringio.py ...........................
module/_io/test/apptest_textio.py ..............................s..................
module/_io/test/test_bufferedio.py .......................................................................ss................................
module/_io/test/test_fileio.py ....................................
module/_io/test/test_interp_textio.py .........
=================== 284 passed, 4 skipped in 220.15 seconds ====================
++ 05:47:45 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 67 items
module/_multibytecodec/test/apptest_codecs.py ...................
module/_multibytecodec/test/apptest_incremental.py ....................
module/_multibytecodec/test/apptest_stream.py .....
module/_multibytecodec/test/test_c_codecs.py ..................s
module/_multibytecodec/test/test_multibtye_codecs.py ...
module/_multibytecodec/test/test_translation.py s
==================== 65 passed, 2 skipped in 67.37 seconds =====================
++ 05:48:58 starting module/_multiprocessing/test [59 started in total]
__ module/_minimal_curses/test [57 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 6 items
module/_minimal_curses/test/test_curses.py ......
========================== 6 passed in 173.71 seconds ==========================
++ 05:49:07 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 5 items
module/_opcode/test/apptest_opcode.py .....
========================== 5 passed in 27.89 seconds ===========================
++ 05:49:40 starting module/_pickle/test [61 started in total]
__ module/_multiprocessing/test [59 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/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 ...sssss.s
module/_multiprocessing/test/test_win32.py s
module/_multiprocessing/test/test_ztranslation.py .
===================== 5 passed, 8 skipped in 46.42 seconds =====================
++ 05:49:50 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 1 items
module/_pickle_support/test/apptest__pickle_support.py .
========================== 1 passed in 17.02 seconds ===========================
++ 05:50:10 starting module/_posixsubprocess/test [63 started in total]
__ module/_pickle/test [61 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 108 items
module/_pickle/test/apptest_optional_frames.py ..
module/_pickle/test/apptest_pickle.py ..............................................................s................
module/_pickle/test/apptest_pypy_extensions.py ...........................
=================== 107 passed, 1 skipped in 120.50 seconds ====================
++ 05:51:43 starting module/_pypyjson/test [64 started in total]
__ module/_posixsubprocess/test [62 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/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 118.50 seconds =====================
++ 05:52:13 starting module/_random/test [65 started in total]
__ module/_pypyjson/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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 57 items
module/_pypyjson/test/apptest__pypyjson.py ..........
module/_pypyjson/test/test__pypyjson.py ............................................
module/_pypyjson/test/test_simd.py ...
========================== 57 passed in 58.24 seconds ==========================
++ 05:52:49 starting module/_rawffi/alt/test [66 started in total]
__ module/_random/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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 13 items
module/_random/test/test_random.py ............
module/_random/test/test_ztranslation.py .
========================== 13 passed in 40.72 seconds ==========================
++ 05:52:58 starting module/_rawffi/test [67 started in total]
__ module/_rawffi/alt/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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 73 items
module/_rawffi/alt/test/test_ffitype.py .....
module/_rawffi/alt/test/test_funcptr.py ..................................ssssss.s
module/_rawffi/alt/test/test_struct.py ...............
module/_rawffi/alt/test/test_type_converter.py ...........
==================== 66 passed, 7 skipped in 29.83 seconds =====================
++ 05:53:22 starting module/_socket/test [68 started in total]
__ module/_rawffi/test [66 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 86 items
module/_rawffi/test/apptest_rawffi.py ..
module/_rawffi/test/test__rawffi.py ......s.............................................s..........s......
module/_rawffi/test/test_exit.py .
module/_rawffi/test/test_nested.py ......
module/_rawffi/test/test_struct.py ...
module/_rawffi/test/test_tracker.py ...
module/_rawffi/test/test_ztranslation.py .
==================== 83 passed, 3 skipped in 126.23 seconds ====================
n: 2
Arg 0: 3
Arg 1: 15
++ 05:55:08 starting module/_sre/test [69 started in total]
__ module/_socket/test [67 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/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 202.81 seconds ===============
++ 05:56:52 starting module/_vmprof/test [70 started in total]
__ module/_sre/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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/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 101.60 seconds =========================
++ 05:56:57 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 22 items
module/_warnings/test/apptest_warnings.py ........s.s..........
module/_warnings/test/test_warnings.py .
==================== 20 passed, 2 skipped in 41.31 seconds =====================
++ 05:57:42 starting module/_weakref/test [72 started in total]
__ module/_vmprof/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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 7 items
module/_vmprof/test/test__vmprof.py ....s
module/_vmprof/test/test_direct.py ..
===================== 6 passed, 1 skipped in 53.21 seconds =====================
++ 05:57:50 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 0 items / 1 skipped
========================== 1 skipped in 0.32 seconds ===========================
++ 05:57:52 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 43 items
module/_weakref/test/apptest_weakref.py ...........................................
========================== 43 passed in 64.06 seconds ==========================
++ 05:58:47 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 2 items
module/atexit/test/apptest_atexit.py ..
========================== 2 passed in 32.55 seconds ===========================
++ 05:59:25 starting module/binascii/test [76 started in total]
__ module/array/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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 64 items
module/array/test/apptest_array.py ...
module/array/test/test_array.py .....................s..................s...................
module/array/test/test_ztranslation.py .
==================== 62 passed, 2 skipped in 124.18 seconds ====================
++ 06:00:03 starting module/bz2/test [77 started in total]
__ module/binascii/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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 18 items
module/binascii/test/test_binascii.py ..................
========================== 18 passed in 36.67 seconds ==========================
++ 06:00:04 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 18 items
module/cmath/test/test_cmath.py ..................
========================== 18 passed in 19.43 seconds ==========================
++ 06:00:24 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 4 items
module/cpyext/test/test_api.py EE..
==================================== ERRORS ====================================
______________ ERROR at setup of TestConversion.test_conversions _______________
item = <Function 'test_conversions'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tool/pytest/objspace.py:24: in gettestobjspace
space = maketestobjspace(config)
tool/pytest/objspace.py:34: in maketestobjspace
space = make_objspace(config)
tool/option.py:33: in make_objspace
return StdObjSpace(config)
interpreter/baseobjspace.py:481: in __init__
self.initialize()
objspace/std/objspace.py:118: in initialize
self.setup_builtin_modules()
interpreter/baseobjspace.py:739: in setup_builtin_modules
self.fromcache(State).build_api()
module/cpyext/state.py:128: in build_api
self.api_lib = str(api.build_bridge(self.space))
module/cpyext/api.py:1468: in build_bridge
builder.attach_all(space)
module/cpyext/api.py:1535: in attach_all
attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1497: in attach_recursively
make_ref(space, w_type))
module/cpyext/pyobject.py:510: in make_ref
return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:483: in get_pyobj_and_incref
pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445: in as_pyobj
py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:326: in create_ref
track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:375: in track_reference
w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj
rawrefcount.create_link_pypy(self, py_obj)
../rpython/rlib/rawrefcount.py:187: in create_link_pypy
assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:102: in _ob_link_get
return ob.c_ob_pypy_link
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f9312074710>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7f9321fa9d60>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 32.69 seconds ======================
++ 06:01:22 starting module/cpyext/test/test_arraymodule.py [80 started in total]
__ module/bz2/test [78 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 53 items
module/bz2/test/apptest_bz2_compdecomp.py .s...
module/bz2/test/test_bz2_compdecomp.py ..s.............
module/bz2/test/test_bz2_file.py ............................
module/bz2/test/test_interpbz2.py ...
module/bz2/test/test_large.py s
==================== 50 passed, 3 skipped in 91.54 seconds =====================
++ 06:01:38 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 3 items
module/cpyext/test/test_async_iter.py EEE
==================================== ERRORS ====================================
_______________ ERROR at setup of AppTestAsyncIter.test_asyncgen _______________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x00007f961a375e20>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f962805c9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f9659d2dae0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f963806ca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f963806ca60>]
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 0x00007f9659d2dae0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f963806ca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f963806ca60>]
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 0x00007f961a4ad240>
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 0x00007f961a4bc260>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f961a4bc260>
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 0x00007f961a4abc90>
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 0x00007f961a4abc90>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f961a4abc90>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f961a4abc90>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f9609b00fe0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f9609d84e20>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e623768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e623748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e627898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f96481fd788>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f961a4ce250>, <W_TypeObject 'GenericAlias' at 0x7f96091937f8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f961a3ccb48>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f961a3ccb48>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f961a3ccb48>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f961a3ccb48>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f95f00dac40>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f961a3ccb48>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f961a3ccb48>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f95f00dac40>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f961a3ccb48>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f95f00dac40>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f95f00dac40>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f95f00dac40>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f9648830e30>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f962805c9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f9659d2dae0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f963806ca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f963806ca60>]
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 0x00007f9659d2dae0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f963806ca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f963806ca60>]
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 0x00007f95f832ed68>
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 0x00007f95e83b70a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f95e83b70a0>
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 0x00007f95e83c97c0>
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 0x00007f95e83c97c0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f95e83c97c0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f95e83c97c0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f95e845f920>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f96283fc8a8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e85d768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e85d748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e861898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f96481fd788>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f95e83c9d38>, <W_TypeObject 'GenericAlias' at 0x7f96595de720>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f9648106f38>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f9648106f38>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f9648106f38>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f9648106f38>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f9607feafc0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f9648106f38>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f9648106f38>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f9607feafc0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f9648106f38>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f9607feafc0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f9607feafc0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f9607feafc0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f9608aad808>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f962805c9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f9659d2dae0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f963806ca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f963806ca60>]
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 0x00007f9659d2dae0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f963806ca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f963806ca60>]
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 0x00007f96595f89a8>
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 0x00007f965a036f20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f965a036f20>
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 0x00007f96099d41a8>
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 0x00007f96099d41a8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f96099d41a8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f96099d41a8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f963a0f0360>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f963a32a790>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e9aa768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e9aa748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e9ae898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f96481fd788>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f96099d4720>, <W_TypeObject 'GenericAlias' at 0x7f9659e82100>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f965a1086e8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f965a1086e8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f965a1086e8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f965a1086e8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f95f00a9160>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f965a1086e8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f965a1086e8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f95f00a9160>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f965a1086e8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f95f00a9160>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f95f00a9160>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f95f00a9160>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 45.31 seconds ===========================
++ 06:02:43 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 4 items
module/cpyext/test/test_boolobject.py EEEE
==================================== ERRORS ====================================
________________ ERROR at setup of TestBoolObject.test_fromlong ________________
item = <Function 'test_fromlong'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tool/pytest/objspace.py:24: in gettestobjspace
space = maketestobjspace(config)
tool/pytest/objspace.py:34: in maketestobjspace
space = make_objspace(config)
tool/option.py:33: in make_objspace
return StdObjSpace(config)
interpreter/baseobjspace.py:481: in __init__
self.initialize()
objspace/std/objspace.py:118: in initialize
self.setup_builtin_modules()
interpreter/baseobjspace.py:739: in setup_builtin_modules
self.fromcache(State).build_api()
module/cpyext/state.py:128: in build_api
self.api_lib = str(api.build_bridge(self.space))
module/cpyext/api.py:1468: in build_bridge
builder.attach_all(space)
module/cpyext/api.py:1535: in attach_all
attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1497: in attach_recursively
make_ref(space, w_type))
module/cpyext/pyobject.py:510: in make_ref
return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:483: in get_pyobj_and_incref
pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445: in as_pyobj
py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:326: in create_ref
track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:375: in track_reference
w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj
rawrefcount.create_link_pypy(self, py_obj)
../rpython/rlib/rawrefcount.py:187: in create_link_pypy
assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:102: in _ob_link_get
return ob.c_ob_pypy_link
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fbebdf06d70>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fbee05df8f8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fbf0021c9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fbf21614fe0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fbf003f49e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fbf003f4a20>]
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 0x00007fbf21614fe0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fbf003f49e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fbf003f4a20>]
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 0x00007fbf018f8778>
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 0x00007fbf018b0ea0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fbf018b0ea0>
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 0x00007fbf018e2410>
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 0x00007fbf018e2410>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fbf018e2410>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fbf018e2410>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fbf01889e20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fbf209fdec0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e8ed778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e8ed758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e8f18a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fbee87d6e58>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fbf018e2988>, <W_TypeObject 'GenericAlias' at 0x7fbeea533a60>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbeea6ac9f8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbeea6ac9f8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbeea6ac9f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbeea6ac9f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fbebdf8efc0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fbeea6ac9f8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fbeea6ac9f8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fbebdf8efc0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fbeea6ac9f8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fbebdf8efc0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fbebdf8efc0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fbebdf8efc0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fbeead5dc40>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fbf0021c9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fbf21614fe0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fbf003f49e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fbf003f4a20>]
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 0x00007fbf21614fe0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fbf003f49e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fbf003f4a20>]
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 0x00007fbeeabc1e48>
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 0x00007fbeeb6334a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fbeeb6334a0>
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 0x00007fbeeb6794b0>
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 0x00007fbeeb6794b0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fbeeb6794b0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fbeeb6794b0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fbf21aa53a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fbf21aa2918>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10ea3c778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10ea3c758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10ea408a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fbee87d6e58>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fbeeb679a28>, <W_TypeObject 'GenericAlias' at 0x7fbf0199c4b8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbeeb3474e8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbeeb3474e8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbeeb3474e8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbeeb3474e8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fbebe250160>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fbeeb3474e8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fbeeb3474e8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fbebe250160>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fbeeb3474e8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fbebe250160>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fbebe250160>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fbebe250160>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fbf129e29f8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fbf0021c9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fbf21614fe0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fbf003f49e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fbf003f4a20>]
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 0x00007fbf21614fe0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fbf003f49e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fbf003f4a20>]
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 0x00007fbf0186b3f8>
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 0x00007fbf11c683a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fbf11c683a0>
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 0x00007fbee04738d8>
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 0x00007fbee04738d8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fbee04738d8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fbee04738d8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fbf015ba6e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fbf216b4d08>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10eb67778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10eb67758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10eb6b8a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fbee87d6e58>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fbee0466480>, <W_TypeObject 'GenericAlias' at 0x7fbeeae30838>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbf219f99b8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbf219f99b8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbf219f99b8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbf219f99b8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fbebe11bd10>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fbf219f99b8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fbf219f99b8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fbebe11bd10>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fbf219f99b8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fbebe11bd10>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fbebe11bd10>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fbebe11bd10>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 58.77 seconds ===========================
++ 06:04:04 starting module/cpyext/test/test_borrow.py [83 started in total]
__ module/_cffi_backend/test [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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 468 items
module/_cffi_backend/test/test_c.py ................................................................................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 0x00007f87f4486188>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f2e525e8>
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 0x00007f87d21fc020>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87d21fc020>
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 0x00007f87a439e410>
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 0x00007f87a439e410>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87a439e410>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87a439e410>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87f3079b20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d4c70090>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1107ed750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x1107ed730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1107f1880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87a439ef70>, <W_TypeObject 'GenericAlias' at 0x7f87d536f7f8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d5536fe0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d5536fe0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d5536fe0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d5536fe0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dfa78a0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87d5536fe0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87d5536fe0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dfa78a0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87d5536fe0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dfa78a0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dfa78a0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dfa78a0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87f51adcb8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f53dcc28>
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 0x00007f87f53d45a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87f53d45a0>
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 0x00007f87d5e47b78>
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 0x00007f87d5e47b78>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87d5e47b78>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87d5e47b78>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87c1b4ebe0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87e180cbf0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b18750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110b18730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b1c880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87f53de138>, <W_TypeObject 'GenericAlias' at 0x7f87a5e14138>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f58f3f68>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f58f3f68>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f58f3f68>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f58f3f68>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e448870>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87f58f3f68>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87f58f3f68>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e448870>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87f58f3f68>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e448870>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e448870>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e448870>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d72c99e8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87e1972660>
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 0x00007f87d7cf3ca0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87d7cf3ca0>
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 0x00007f87d7cfd788>
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 0x00007f87d7cfd788>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87d7cfd788>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87d7cfd788>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a62f1260>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87f5a47520>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be1750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110be1730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be5880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87d7cfdd00>, <W_TypeObject 'GenericAlias' at 0x7f87d7ec8138>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87c1b82ec8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87c1b82ec8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87c1b82ec8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87c1b82ec8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e637d20>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87c1b82ec8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87c1b82ec8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e637d20>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87c1b82ec8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e637d20>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e637d20>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e637d20>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87e1cbc7a0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87e1cdeed0>
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 0x00007f87e1cc7aa0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87e1cc7aa0>
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 0x00007f87e1cdc720>
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 0x00007f87e1cdc720>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87e1cdc720>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87e1cdc720>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87b5fed160>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87a71c81a8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110caa750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110caa730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110cae880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87e1cdcc98>, <W_TypeObject 'GenericAlias' at 0x7f87a7362c98>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e1e287c8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e1e287c8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e1e287c8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e1e287c8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5ef370>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87e1e287c8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87e1e287c8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5ef370>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87e1e287c8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5ef370>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5ef370>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5ef370>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87e12775b0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87b4443380>
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 0x00007f87f25fcd20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87f25fcd20>
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 0x00007f87f5005168>
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 0x00007f87f5005168>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87f5005168>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87f5005168>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87c10d0760>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87e15657c0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be1750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110be1730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be5880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87f50056e0>, <W_TypeObject 'GenericAlias' at 0x7f87f57a0f70>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b59673d0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b59673d0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b59673d0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b59673d0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877df21a70>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87b59673d0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87b59673d0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877df21a70>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87b59673d0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877df21a70>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877df21a70>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877df21a70>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87b461d2e0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87d4ccde98>
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 0x00007f87d3173120>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87d3173120>
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 0x00007f87e194bbe8>
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 0x00007f87e194bbe8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87e194bbe8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87e194bbe8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87b3f385a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87f4f2a560>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d73750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110d73730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d77880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87e19521a8>, <W_TypeObject 'GenericAlias' at 0x7f87b4737e50>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d4af96e0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d4af96e0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d4af96e0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d4af96e0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e06ea60>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87d4af96e0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87d4af96e0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e06ea60>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87d4af96e0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e06ea60>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e06ea60>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e06ea60>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87b582d970>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87e15f2048>
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 0x00007f87d7e933a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87d7e933a0>
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 0x00007f87d4e8d280>
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 0x00007f87d4e8d280>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87d4e8d280>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87d4e8d280>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a63f1ee0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d5ef1088>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e3c750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110e3c730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e40880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87d4e8d7f8>, <W_TypeObject 'GenericAlias' at 0x7f87b4fad2f0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b5cebec0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b5cebec0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b5cebec0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b5cebec0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877da51d10>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87b5cebec0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87b5cebec0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877da51d10>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87b5cebec0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877da51d10>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877da51d10>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877da51d10>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87f59f6980>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f59c6340>
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 0x00007f87d5bd0160>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87d5bd0160>
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 0x00007f87d7861d38>
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 0x00007f87d7861d38>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87d7861d38>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87d7861d38>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87d5a6cd20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d5c4f168>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f05750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110f05730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f09880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87d5bd62f8>, <W_TypeObject 'GenericAlias' at 0x7f87a65399b8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d7022218>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d7022218>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d7022218>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d7022218>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8f4dd0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87d7022218>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87d7022218>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8f4dd0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87d7022218>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8f4dd0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8f4dd0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8f4dd0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a6f8d628>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87d69f7ee8>
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 0x00007f87d69fbd20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87d69fbd20>
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 0x00007f87d6a01670>
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 0x00007f87d6a01670>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87d6a01670>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87d6a01670>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87f672abe0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87f6803130>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110fce750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110fce730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110fd2880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87d6a01be8>, <W_TypeObject 'GenericAlias' at 0x7f87a58d8cd0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f69029f8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f69029f8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f69029f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f69029f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e79e0e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87f69029f8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87f69029f8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e79e0e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87f69029f8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e79e0e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e79e0e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e79e0e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87b7ae2638>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87d63accf0>
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 0x00007f87d63a5ba0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87d63a5ba0>
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 0x00007f87d64145d0>
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 0x00007f87d64145d0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87d64145d0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87d64145d0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87f6f662e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d64e32b8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x111097750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x111097730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11109b880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87d6414b48>, <W_TypeObject 'GenericAlias' at 0x7f87a68e1558>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e20bcde8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e20bcde8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e20bcde8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e20bcde8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877deb0890>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87e20bcde8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87e20bcde8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877deb0890>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87e20bcde8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877deb0890>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877deb0890>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877deb0890>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f8770831cb8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f8790d14250>
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 0x00007f87d247de60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87d247de60>
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 0x00007f87a69c9e88>
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 0x00007f87a69c9e88>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87a69c9e88>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87a69c9e88>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87900ddaa0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87a15f1088>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b18750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110b18730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b1c880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87a73ea448>, <W_TypeObject 'GenericAlias' at 0x7f87b44c62f8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a43c0f00>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a43c0f00>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a43c0f00>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a43c0f00>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dc9b5f0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87a43c0f00>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87a43c0f00>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dc9b5f0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87a43c0f00>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dc9b5f0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dc9b5f0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dc9b5f0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a44ab088>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f3b7d8d0>
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 0x00007f87c12616a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87c12616a0>
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 0x00007f87f56a9280>
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 0x00007f87f56a9280>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87f56a9280>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87f56a9280>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a2a8c9e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87b59c71d8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be1750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110be1730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be5880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87f56a97f8>, <W_TypeObject 'GenericAlias' at 0x7f87a7189050>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87700b2de8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87700b2de8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87700b2de8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87700b2de8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877ddb0c20>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87700b2de8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87700b2de8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877ddb0c20>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87700b2de8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877ddb0c20>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877ddb0c20>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877ddb0c20>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f8790c402f0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87b4030188>
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 0x00007f87f33377a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87f33377a0>
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 0x00007f87d7ee0480>
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 0x00007f87d7ee0480>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87d7ee0480>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87d7ee0480>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f8790d3ec20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87708b97f8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d73750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110d73730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d77880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87d7ee09f8>, <W_TypeObject 'GenericAlias' at 0x7f87d5671830>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d56eb9f0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d56eb9f0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d56eb9f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d56eb9f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e07ac90>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87d56eb9f0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87d56eb9f0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e07ac90>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87d56eb9f0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e07ac90>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e07ac90>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e07ac90>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87e1820638>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87d4fdbd08>
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 0x00007f87f60bdc60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87f60bdc60>
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 0x00007f87a4d835c8>
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 0x00007f87a4d835c8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87a4d835c8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87a4d835c8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f877005f7a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d55c6b80>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e3c750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110e3c730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e40880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87a4d83b40>, <W_TypeObject 'GenericAlias' at 0x7f87f57b7e88>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b5f4b788>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b5f4b788>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b5f4b788>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b5f4b788>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e0c7d20>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87b5f4b788>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87b5f4b788>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e0c7d20>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87b5f4b788>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e0c7d20>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e0c7d20>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e0c7d20>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d7e71100>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f8790e15e70>
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 0x00007f87b5331120>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b5331120>
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 0x00007f87b5316de8>
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 0x00007f87b5316de8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87b5316de8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87b5316de8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87f54f1d20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87a6c3abb8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f05750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110f05730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f09880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87b5317360>, <W_TypeObject 'GenericAlias' at 0x7f87d6666790>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f877051c138>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f877051c138>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f877051c138>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f877051c138>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8164d0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f877051c138>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f877051c138>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8164d0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f877051c138>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8164d0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8164d0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8164d0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a54cc3e0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87a61b3f60>
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 0x00007f87f6ca90a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87f6ca90a0>
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 0x00007f87f6cdc758>
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 0x00007f87f6cdc758>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87f6cdc758>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87f6cdc758>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87f6ac6e60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d7b893d0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110fce750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110fce730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110fd2880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87f6cdccd0>, <W_TypeObject 'GenericAlias' at 0x7f87f5288870>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f52630f8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f52630f8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f52630f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f52630f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876afa4bf0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87f52630f8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87f52630f8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876afa4bf0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87f52630f8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876afa4bf0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876afa4bf0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876afa4bf0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d69089f8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87a7366a70>
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 0x00007f87e1fb9d20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87e1fb9d20>
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 0x00007f87e2014b48>
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 0x00007f87e2014b48>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87e2014b48>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87e2014b48>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f8770912be0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d7bdead8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x111160750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x111160730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x111164880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87e20150c0>, <W_TypeObject 'GenericAlias' at 0x7f87a6a34100>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a6a7efa8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a6a7efa8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a6a7efa8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a6a7efa8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e621700>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87a6a7efa8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87a6a7efa8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e621700>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87a6a7efa8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e621700>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e621700>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e621700>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a78c4980>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87a5939858>
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 0x00007f87b7f6e6e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b7f6e6e0>
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 0x00007f87715c9050>
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 0x00007f87715c9050>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87715c9050>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87715c9050>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87b5435f60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87a363d360>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b18750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110b18730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b1c880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87715c95c8>, <W_TypeObject 'GenericAlias' at 0x7f87b4394720>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d2736c28>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d2736c28>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d2736c28>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d2736c28>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877b240ba0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87d2736c28>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87d2736c28>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877b240ba0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87d2736c28>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877b240ba0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877b240ba0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877b240ba0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87f4487e98>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87c16e4db8>
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 0x00007f87c1003aa0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87c1003aa0>
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 0x00007f87d5d555c8>
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 0x00007f87d5d555c8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87d5d555c8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87d5d555c8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a3082260>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87a5ba8d78>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be1750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110be1730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be5880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87d5d55b40>, <W_TypeObject 'GenericAlias' at 0x7f87f5a132b8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b5a79868>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b5a79868>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b5a79868>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b5a79868>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dc9b010>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87b5a79868>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87b5a79868>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dc9b010>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87b5a79868>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dc9b010>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dc9b010>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dc9b010>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a4bd6020>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87b47f4fc0>
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 0x00007f87f2548b20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87f2548b20>
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 0x00007f87d7b04678>
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 0x00007f87d7b04678>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87d7b04678>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87d7b04678>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87b2964660>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87e21c3e50>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110caa750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110caa730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110cae880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87d7b04bf0>, <W_TypeObject 'GenericAlias' at 0x7f87c1c55718>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87c1bf3360>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87c1bf3360>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87c1bf3360>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87c1bf3360>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5bc5e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87c1bf3360>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87c1bf3360>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5bc5e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87c1bf3360>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5bc5e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5bc5e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5bc5e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87809b46b0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f4dc5628>
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 0x00007f87d6078b20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87d6078b20>
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 0x00007f87b5be5088>
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 0x00007f87b5be5088>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87b5be5088>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87b5be5088>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87d6079de0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f8780c32870>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d73750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110d73730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d77880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87b5be5600>, <W_TypeObject 'GenericAlias' at 0x7f87f41c52f0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a4f68058>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a4f68058>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a4f68058>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a4f68058>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f878afce2e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87a4f68058>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87a4f68058>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f878afce2e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87a4f68058>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f878afce2e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f878afce2e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f878afce2e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87f5a5e458>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87b4bdcd40>
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 0x00007f87b4e528a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b4e528a0>
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 0x00007f87d7257750>
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 0x00007f87d7257750>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87d7257750>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87d7257750>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87b62b5ba0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87b6dfb8a0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e3c750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110e3c730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e40880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87d7257cc8>, <W_TypeObject 'GenericAlias' at 0x7f87d75b1d70>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d75ad558>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d75ad558>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d75ad558>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d75ad558>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e521390>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87d75ad558>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87d75ad558>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e521390>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87d75ad558>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e521390>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e521390>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e521390>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a6f8cdb8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87b589d2b8>
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 0x00007f87a6877560>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87a6877560>
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 0x00007f87a6839600>
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 0x00007f87a6839600>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87a6839600>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87a6839600>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87d69a2fe0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d76b23a0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f05750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110f05730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f09880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87a6839b78>, <W_TypeObject 'GenericAlias' at 0x7f87a65cf7c0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a5eaed78>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a5eaed78>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a5eaed78>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a5eaed78>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e48d1e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87a5eaed78>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87a5eaed78>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e48d1e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87a5eaed78>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e48d1e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e48d1e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e48d1e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d6507808>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87d7f77e70>
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 0x00007f87b70021e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b70021e0>
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 0x00007f87b6fec838>
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 0x00007f87b6fec838>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87b6fec838>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87b6fec838>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a70132e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d6e6bf68>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110fce750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110fce730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110fd2880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87b6fecdb0>, <W_TypeObject 'GenericAlias' at 0x7f87b6212790>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b620a838>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b620a838>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b620a838>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b620a838>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b3d3e90>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87b620a838>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87b620a838>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b3d3e90>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87b620a838>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b3d3e90>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b3d3e90>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b3d3e90>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87b679aa70>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f6f62ea8>
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 0x00007f8771923ca0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f8771923ca0>
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 0x00007f87719684f0>
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 0x00007f87719684f0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87719684f0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87719684f0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87c2186a60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87f6abcaa0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b18750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110b18730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b1c880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f8771968a68>, <W_TypeObject 'GenericAlias' at 0x7f87d1b14950>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b2352918>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b2352918>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b2352918>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b2352918>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877bf44dd0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87b2352918>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87b2352918>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877bf44dd0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87b2352918>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877bf44dd0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877bf44dd0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877bf44dd0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d48c2020>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87b1c22a48>
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 0x00007f87e04ac360>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87e04ac360>
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 0x00007f87b4f61d70>
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 0x00007f87b4f61d70>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87b4f61d70>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87b4f61d70>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87d26249a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87a52caa30>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be1750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110be1730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be5880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87e15ca330>, <W_TypeObject 'GenericAlias' at 0x7f87d72fdde0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d7cd6988>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d7cd6988>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d7cd6988>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d7cd6988>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dce99f0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87d7cd6988>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87d7cd6988>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dce99f0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87d7cd6988>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dce99f0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dce99f0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dce99f0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d4c7c110>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87b3f79088>
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 0x00007f87b1783ae0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b1783ae0>
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 0x00007f87a6a40410>
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 0x00007f87a6a40410>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87a6a40410>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87a6a40410>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87b17775a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f8790b0cf00>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110caa750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110caa730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110cae880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87a6a40c60>, <W_TypeObject 'GenericAlias' at 0x7f87910c52b8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8770a78838>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8770a78838>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8770a78838>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8770a78838>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e0ceae0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f8770a78838>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f8770a78838>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e0ceae0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f8770a78838>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e0ceae0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e0ceae0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e0ceae0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87809b4458>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87908a0908>
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 0x00007f87e18ec960>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87e18ec960>
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 0x00007f87a608e1a8>
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 0x00007f87a608e1a8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87a608e1a8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87a608e1a8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87f57a59e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87e1410de8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d73750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110d73730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d77880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87a608e720>, <W_TypeObject 'GenericAlias' at 0x7f87f6f85788>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a5094f00>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a5094f00>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a5094f00>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a5094f00>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5685f0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87a5094f00>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87a5094f00>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5685f0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87a5094f00>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5685f0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5685f0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5685f0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87b5b1fbc8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87d504dc68>
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 0x00007f87f6fafca0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87f6fafca0>
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 0x00007f87704d92f0>
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 0x00007f87704d92f0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87704d92f0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87704d92f0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87f6fc30e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87a4ef5e88>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e3c750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110e3c730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e40880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87704d9868>, <W_TypeObject 'GenericAlias' at 0x7f87e12361a8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a6eba138>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a6eba138>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a6eba138>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a6eba138>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e169660>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87a6eba138>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87a6eba138>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e169660>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87a6eba138>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e169660>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e169660>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e169660>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a57b8f20>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87d56622c8>
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 0x00007f87f4ad3720>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87f4ad3720>
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 0x00007f87e211a838>
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 0x00007f87e211a838>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87e211a838>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87e211a838>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87d56fa760>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87e13a0e20>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f05750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110f05730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f09880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87e211adb0>, <W_TypeObject 'GenericAlias' at 0x7f87f5473868>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f54b1360>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f54b1360>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f54b1360>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f54b1360>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e680de0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87f54b1360>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87f54b1360>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e680de0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87f54b1360>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e680de0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e680de0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e680de0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d7bc74c0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87b5996638>
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 0x00007f87b6a3a420>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b6a3a420>
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 0x00007f87b6a39b78>
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 0x00007f87b6a39b78>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87b6a39b78>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87b6a39b78>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87b6a3b7a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87f72846b0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x111097750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x111097730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11109b880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f877137c138>, <W_TypeObject 'GenericAlias' at 0x7f87b529a020>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b52f7280>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b52f7280>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b52f7280>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b52f7280>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e292d50>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87b52f7280>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87b52f7280>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e292d50>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87b52f7280>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e292d50>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e292d50>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e292d50>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a5a1dc40>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87a71c1ec0>
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 0x00007f87a7517ce0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87a7517ce0>
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 0x00007f87e2324cd0>
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 0x00007f87e2324cd0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87e2324cd0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87e2324cd0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87e22e6d20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87707b1ad0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x111229750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x111229730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11122d880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87e2325248>, <W_TypeObject 'GenericAlias' at 0x7f877158fa28>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d7b4a640>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d7b4a640>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d7b4a640>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d7b4a640>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c59b5a0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87d7b4a640>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87d7b4a640>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c59b5a0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87d7b4a640>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c59b5a0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c59b5a0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c59b5a0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d64ca098>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f71af560>
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 0x00007f87d25574a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87d25574a0>
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 0x00007f87d4f3f9f0>
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 0x00007f87d4f3f9f0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87d4f3f9f0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87d4f3f9f0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a1714e20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87b49c9478>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b18750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110b18730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b1c880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87d4f55248>, <W_TypeObject 'GenericAlias' at 0x7f878091fbe8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e1744c60>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e1744c60>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e1744c60>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e1744c60>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dba31c0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87e1744c60>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87e1744c60>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dba31c0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87e1744c60>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dba31c0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dba31c0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dba31c0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87b45da728>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87c171b510>
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 0x00007f87b25fd420>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b25fd420>
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 0x00007f87f584d520>
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 0x00007f87f584d520>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87f584d520>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87f584d520>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a2856960>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87b48a61a8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be1750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110be1730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be5880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87f584da98>, <W_TypeObject 'GenericAlias' at 0x7f87e21c2368>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e22754e8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e22754e8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e22754e8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e22754e8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877df9a660>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87e22754e8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87e22754e8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877df9a660>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87e22754e8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877df9a660>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877df9a660>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877df9a660>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d51a6a70>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87a4353b50>
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 0x00007f87f513b020>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87f513b020>
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 0x00007f87d52f79f0>
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 0x00007f87d52f79f0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87d52f79f0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87d52f79f0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87f514ea20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87f441f088>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110caa750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110caa730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110cae880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87d52f7f68>, <W_TypeObject 'GenericAlias' at 0x7f87d5fccdb0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d5f80330>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d5f80330>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d5f80330>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d5f80330>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e18bc10>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87d5f80330>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87d5f80330>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e18bc10>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87d5f80330>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e18bc10>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e18bc10>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e18bc10>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87e1988ae8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f4b241b0>
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 0x00007f87f68baaa0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87f68baaa0>
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 0x00007f87a54b7328>
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 0x00007f87a54b7328>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87a54b7328>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87a54b7328>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87f68bba60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87f589bda8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d73750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110d73730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d77880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87a54b78a0>, <W_TypeObject 'GenericAlias' at 0x7f87f564e838>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5696800>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5696800>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5696800>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5696800>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e2a1360>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5696800>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87f5696800>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e2a1360>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87f5696800>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e2a1360>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e2a1360>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e2a1360>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87f658f448>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87a511fc18>
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 0x00007f87a75f2ea0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87a75f2ea0>
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 0x00007f87f698b8a0>
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 0x00007f87f698b8a0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87f698b8a0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87f698b8a0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87d6c05120>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d703f980>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e3c750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110e3c730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e40880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87f698be18>, <W_TypeObject 'GenericAlias' at 0x7f87b2fb43d8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b2fbc6e8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b2fbc6e8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b2fbc6e8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b2fbc6e8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8d1e50>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87b2fbc6e8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87b2fbc6e8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8d1e50>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87b2fbc6e8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8d1e50>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8d1e50>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8d1e50>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d6507c40>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87d5d867f0>
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 0x00007f87b659ca60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b659ca60>
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 0x00007f87b6561600>
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 0x00007f87b6561600>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87b6561600>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87b6561600>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87b51a0020>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87b51a2950>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f05750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110f05730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f09880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87b6561b78>, <W_TypeObject 'GenericAlias' at 0x7f87b788c4f0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8770e64918>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8770e64918>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8770e64918>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8770e64918>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e4e4d90>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f8770e64918>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f8770e64918>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e4e4d90>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f8770e64918>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e4e4d90>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e4e4d90>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e4e4d90>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d6887358>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f59e6368>
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 0x00007f8771921a20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f8771921a20>
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 0x00007f87718d1da8>
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 0x00007f87718d1da8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87718d1da8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87718d1da8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87e1e90ca0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87f7089e88>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x111097750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x111097730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11109b880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87d60c0368>, <W_TypeObject 'GenericAlias' at 0x7f87b565b9f0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87c0820950>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87c0820950>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87c0820950>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87c0820950>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c50b690>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87c0820950>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87c0820950>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c50b690>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87c0820950>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c50b690>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c50b690>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c50b690>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87b679ad40>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87d7f6aed0>
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 0x00007f87d2891e60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87d2891e60>
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 0x00007f87d4fc8330>
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 0x00007f87d4fc8330>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87d4fc8330>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87d4fc8330>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a1ca1e20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87b49edde0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b18750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110b18730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b1c880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87d4fc88a8>, <W_TypeObject 'GenericAlias' at 0x7f87a52ca250>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e1775018>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e1775018>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e1775018>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e1775018>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c440a20>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87e1775018>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87e1775018>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c440a20>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87e1775018>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c440a20>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c440a20>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c440a20>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87e1276ea8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f8770f8d650>
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 0x00007f87b1810f60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b1810f60>
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 0x00007f87f4383a28>
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 0x00007f87f4383a28>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87f4383a28>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87f4383a28>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87b17ca4e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87a5e994e8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be1750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110be1730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be5880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87f4383fa0>, <W_TypeObject 'GenericAlias' at 0x7f87c18dc6b0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b6ddb398>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b6ddb398>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b6ddb398>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b6ddb398>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877db85d30>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87b6ddb398>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87b6ddb398>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877db85d30>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87b6ddb398>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877db85d30>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877db85d30>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877db85d30>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a4dab628>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87d474a548>
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 0x00007f87809aa7e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87809aa7e0>
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 0x00007f87d50c8a68>
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 0x00007f87d50c8a68>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87d50c8a68>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87d50c8a68>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87809ea8e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f8780a954e8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110caa750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110caa730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110cae880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87d50c8fe0>, <W_TypeObject 'GenericAlias' at 0x7f87b5018918>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87c1930b10>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87c1930b10>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87c1930b10>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87c1930b10>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e599f40>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87c1930b10>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87c1930b10>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e599f40>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87c1930b10>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e599f40>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e599f40>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e599f40>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d72c8728>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87a435c368>
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 0x00007f87f6ff6e20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87f6ff6e20>
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 0x00007f87f688c640>
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 0x00007f87f688c640>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87f688c640>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87f688c640>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87f700c160>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87f5e6b590>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d73750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110d73730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d77880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87f688cbb8>, <W_TypeObject 'GenericAlias' at 0x7f87f42317c0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f41fa560>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f41fa560>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f41fa560>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f41fa560>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e1473f0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87f41fa560>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87f41fa560>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e1473f0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87f41fa560>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e1473f0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e1473f0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e1473f0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a73fa2f0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87d4d25790>
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 0x00007f87a5fe1820>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87a5fe1820>
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 0x00007f87b7be0e90>
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 0x00007f87b7be0e90>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87b7be0e90>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87b7be0e90>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f8770c10b60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87b5334790>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e3c750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110e3c730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e40880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87b7be1408>, <W_TypeObject 'GenericAlias' at 0x7f8770688330>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87706b4640>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87706b4640>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87706b4640>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87706b4640>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f878b0d07e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87706b4640>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87706b4640>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f878b0d07e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87706b4640>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f878b0d07e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f878b0d07e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f878b0d07e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a69f7628>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87b49f5808>
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 0x00007f87b6acd460>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b6acd460>
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 0x00007f87b6a8b558>
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 0x00007f87b6a8b558>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87b6a8b558>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87b6a8b558>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f8780b738a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f879118cbf0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f05750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110f05730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f09880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87b6a8bad0>, <W_TypeObject 'GenericAlias' at 0x7f8770cc6058>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8770ca9210>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8770ca9210>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8770ca9210>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8770ca9210>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e898230>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f8770ca9210>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f8770ca9210>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e898230>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f8770ca9210>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e898230>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e898230>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e898230>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87e21d13d0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87b4fc8250>
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 0x00007f87709910e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87709910e0>
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 0x00007f87709cf6e0>
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 0x00007f87709cf6e0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87709cf6e0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87709cf6e0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a5ed2da0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d77e0e90>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110fce750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110fce730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110fd2880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87709cfc58>, <W_TypeObject 'GenericAlias' at 0x7f87b617e288>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b74e7558>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b74e7558>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b74e7558>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b74e7558>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e497890>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87b74e7558>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87b74e7558>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e497890>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87b74e7558>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e497890>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e497890>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e497890>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f877078d6a0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87a612b7e0>
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 0x00007f87d217b620>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87d217b620>
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 0x00007f87a46876e0>
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 0x00007f87a46876e0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87a46876e0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87a46876e0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a12a2fa0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87f3f99e18>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b18750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110b18730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b1c880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87a467b868>, <W_TypeObject 'GenericAlias' at 0x7f8790aff520>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d48fbbb0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d48fbbb0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d48fbbb0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d48fbbb0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877ddb3460>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87d48fbbb0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87d48fbbb0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877ddb3460>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87d48fbbb0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877ddb3460>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877ddb3460>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877ddb3460>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87f3f0a890>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f6492020>
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 0x00007f87d2fab860>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87d2fab860>
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 0x00007f87b473ba28>
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 0x00007f87b473ba28>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87b473ba28>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87b473ba28>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87d2fcd820>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d6b7de50>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be1750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110be1730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be5880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87b473bfa0>, <W_TypeObject 'GenericAlias' at 0x7f87f6889fa0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a67f6db0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a67f6db0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a67f6db0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a67f6db0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e030760>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87a67f6db0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87a67f6db0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e030760>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87a67f6db0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e030760>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e030760>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e030760>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a4cc5010>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f66eade0>
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 0x00007f87a5209c20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87a5209c20>
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 0x00007f87d6167fa0>
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 0x00007f87d6167fa0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87d6167fa0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87d6167fa0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87808b6560>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87715701e0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110caa750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110caa730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110cae880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87d618e598>, <W_TypeObject 'GenericAlias' at 0x7f87e1fd98d8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b7ba1360>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b7ba1360>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b7ba1360>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b7ba1360>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e4e28a0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87b7ba1360>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87b7ba1360>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e4e28a0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87b7ba1360>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e4e28a0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e4e28a0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e4e28a0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d67ecbd8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87e1043c68>
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 0x00007f87b5042920>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b5042920>
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 0x00007f87d78c2de8>
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 0x00007f87d78c2de8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87d78c2de8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87d78c2de8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87b5043ca0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f8790e28560>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d73750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110d73730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d77880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87d78c3360>, <W_TypeObject 'GenericAlias' at 0x7f87b5367718>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e1e9cbf0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e1e9cbf0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e1e9cbf0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e1e9cbf0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e424530>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87e1e9cbf0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87e1e9cbf0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e424530>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87e1e9cbf0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e424530>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e424530>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e424530>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a73fbcb8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f3ade520>
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 0x00007f87d7508960>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87d7508960>
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 0x00007f87f4854640>
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 0x00007f87f4854640>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87f4854640>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87f4854640>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87d7540860>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f877078a838>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e3c750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110e3c730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e40880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87f4854bb8>, <W_TypeObject 'GenericAlias' at 0x7f87a6636ec8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d5bb2608>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d5bb2608>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d5bb2608>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d5bb2608>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c62cef0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87d5bb2608>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87d5bb2608>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c62cef0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87d5bb2608>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c62cef0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c62cef0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c62cef0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d6febe98>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87d4b72570>
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 0x00007f87f6b878e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87f6b878e0>
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 0x00007f87a59643a0>
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 0x00007f87a59643a0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87a59643a0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87a59643a0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87f6eb6be0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87f51ea8a8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f05750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110f05730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f09880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87a5964918>, <W_TypeObject 'GenericAlias' at 0x7f87f71b3478>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f71ed3d0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f71ed3d0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f71ed3d0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f71ed3d0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876afcb2d0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87f71ed3d0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87f71ed3d0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876afcb2d0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87f71ed3d0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876afcb2d0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876afcb2d0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876afcb2d0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87b52d7970>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87a4f261b0>
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 0x00007f87d58742a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87d58742a0>
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 0x00007f87d58a83d8>
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 0x00007f87d58a83d8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87d58a83d8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87d58a83d8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87d5875320>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d61fad78>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x111160750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x111160730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x111164880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87d58a8950>, <W_TypeObject 'GenericAlias' at 0x7f87e2094608>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e20638a0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e20638a0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e20638a0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e20638a0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e19b140>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87e20638a0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87e20638a0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e19b140>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87e20638a0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e19b140>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e19b140>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e19b140>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87f74d38f8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87a516de20>
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 0x00007f8750097f60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f8750097f60>
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 0x00007f87500e4c60>
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 0x00007f87500e4c60>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87500e4c60>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87500e4c60>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87c2350ae0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87f70f2598>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b18750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110b18730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b1c880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87500e51d8>, <W_TypeObject 'GenericAlias' at 0x7f8790977638>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e0281408>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e0281408>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e0281408>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e0281408>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c493020>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87e0281408>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87e0281408>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c493020>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87e0281408>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c493020>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c493020>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c493020>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d48e07a0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f8790eee7f0>
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 0x00007f87b1b90ae0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b1b90ae0>
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 0x00007f87a51a5558>
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 0x00007f87a51a5558>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87a51a5558>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87a51a5558>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87c0fb00e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87a524cb48>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be1750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110be1730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be5880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87a51c2aa0>, <W_TypeObject 'GenericAlias' at 0x7f87a5f885d0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d6041d70>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d6041d70>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d6041d70>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d6041d70>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e6ec930>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87d6041d70>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87d6041d70>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e6ec930>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87d6041d70>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e6ec930>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e6ec930>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e6ec930>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d49644d0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87809f3948>
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 0x00007f87d28f0da0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87d28f0da0>
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 0x00007f87e1fb16a8>
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 0x00007f87e1fb16a8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87e1fb16a8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87e1fb16a8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87f2bd0e60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87a7880bb8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110caa750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110caa730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110cae880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87e1fb1c20>, <W_TypeObject 'GenericAlias' at 0x7f87f6b230f8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b6fcd1a0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b6fcd1a0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b6fcd1a0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b6fcd1a0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e591b90>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87b6fcd1a0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87b6fcd1a0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e591b90>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87b6fcd1a0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e591b90>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e591b90>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e591b90>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87e1821088>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87b5b7de48>
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 0x00007f87a5cd8360>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87a5cd8360>
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 0x00007f87b56b3210>
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 0x00007f87b56b3210>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87b56b3210>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87b56b3210>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a5cd95a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87f7471f68>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d73750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110d73730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d77880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87b56b3788>, <W_TypeObject 'GenericAlias' at 0x7f87b5006678>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a5e2dbe8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a5e2dbe8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a5e2dbe8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a5e2dbe8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e154140>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87a5e2dbe8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87a5e2dbe8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e154140>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87a5e2dbe8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e154140>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e154140>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e154140>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a71dcea8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87a744c200>
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 0x00007f87a568d120>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87a568d120>
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 0x00007f87e1854608>
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 0x00007f87e1854608>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87e1854608>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87e1854608>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a56383e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87a5782020>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e3c750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110e3c730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e40880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87e1854b80>, <W_TypeObject 'GenericAlias' at 0x7f87d4a03fa0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b785e528>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b785e528>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b785e528>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b785e528>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8296e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87b785e528>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87b785e528>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8296e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87b785e528>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8296e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8296e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8296e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d6feadb8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87b4456ea8>
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 0x00007f87a6e012a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87a6e012a0>
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 0x00007f87714e94b0>
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 0x00007f87714e94b0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87714e94b0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87714e94b0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a75164e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d726dd38>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f05750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110f05730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f09880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87714e9a28>, <W_TypeObject 'GenericAlias' at 0x7f87f5d1e608>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5d23b78>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5d23b78>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5d23b78>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5d23b78>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c659810>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5d23b78>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87f5d23b78>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c659810>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87f5d23b78>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c659810>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c659810>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c659810>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a5a1c5c0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87b3ffd628>
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 0x00007f87b7666020>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b7666020>
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 0x00007f87b6567b08>
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 0x00007f87b6567b08>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87b6567b08>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87b6567b08>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87b7667120>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87b798cc28>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x111097750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x111097730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11109b880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87b76860c8>, <W_TypeObject 'GenericAlias' at 0x7f87b5174218>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b513a170>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b513a170>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b513a170>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b513a170>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b3bf140>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87b513a170>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87b513a170>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b3bf140>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87b513a170>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b3bf140>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b3bf140>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b3bf140>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87b76d78f8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f4d44a70>
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 0x00007f87e22c13a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87e22c13a0>
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 0x00007f87d79fa288>
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 0x00007f87d79fa288>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87d79fa288>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87d79fa288>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87b6092f20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f8790f7d1d8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x111229750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x111229730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11122d880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87d79fa800>, <W_TypeObject 'GenericAlias' at 0x7f87f5e401e0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5e3f590>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5e3f590>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5e3f590>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5e3f590>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b068320>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5e3f590>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87f5e3f590>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b068320>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87f5e3f590>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b068320>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b068320>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b068320>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d7797538>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87d517df38>
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 0x00007f87d2047de0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87d2047de0>
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 0x00007f87a3780b48>
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 0x00007f87a3780b48>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87a3780b48>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87a3780b48>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a10b61e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87f4062410>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b18750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110b18730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b1c880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87b1083d00>, <W_TypeObject 'GenericAlias' at 0x7f87c198e528>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8790aff408>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8790aff408>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8790aff408>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8790aff408>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877db64230>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f8790aff408>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f8790aff408>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877db64230>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f8790aff408>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877db64230>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877db64230>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877db64230>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d29d0f20>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87e17107a0>
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 0x00007f87a28f4820>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87a28f4820>
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 0x00007f87e1deab10>
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 0x00007f87e1deab10>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87e1deab10>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87e1deab10>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a28ab7e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d4f822f8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be1750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110be1730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be5880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87e1dfa608>, <W_TypeObject 'GenericAlias' at 0x7f87d6638448>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a6556c98>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a6556c98>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a6556c98>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a6556c98>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877da11e60>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87a6556c98>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87a6556c98>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877da11e60>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87a6556c98>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877da11e60>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877da11e60>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877da11e60>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a4daa9f8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87a6226d40>
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 0x00007f87f4f2fce0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87f4f2fce0>
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 0x00007f8770bd7328>
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 0x00007f8770bd7328>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f8770bd7328>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f8770bd7328>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a50f31a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d5fc69f8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110caa750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110caa730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110cae880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f8770bd7a28>, <W_TypeObject 'GenericAlias' at 0x7f87f7066d40>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d7b76f38>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d7b76f38>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d7b76f38>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d7b76f38>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e105980>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87d7b76f38>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87d7b76f38>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e105980>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87d7b76f38>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e105980>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e105980>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e105980>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87f5a4ebd8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87b5ff0d90>
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 0x00007f87b5ebf760>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b5ebf760>
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 0x00007f87b49e02f8>
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 0x00007f87b49e02f8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87b49e02f8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87b49e02f8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87b5ef4da0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87b5ed7130>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d73750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110d73730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d77880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87b49e0870>, <W_TypeObject 'GenericAlias' at 0x7f87b76e3e50>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b770db78>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b770db78>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b770db78>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b770db78>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877ddc4e00>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87b770db78>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87b770db78>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877ddc4e00>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87b770db78>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877ddc4e00>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877ddc4e00>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877ddc4e00>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87f68ca548>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87b6d6e9d0>
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 0x00007f87f63ce6a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87f63ce6a0>
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 0x00007f87b51d3b78>
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 0x00007f87b51d3b78>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87b51d3b78>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87b51d3b78>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87f63cf8e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87b5d699f0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e3c750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110e3c730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e40880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87f42a4138>, <W_TypeObject 'GenericAlias' at 0x7f87d5a1a480>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d5a561a8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d5a561a8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d5a561a8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d5a561a8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b3a78c0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87d5a561a8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87d5a561a8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b3a78c0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87d5a561a8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b3a78c0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b3a78c0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b3a78c0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d68873d0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f3bdfe48>
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 0x00007f87b79a9160>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b79a9160>
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 0x00007f87e2203868>
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 0x00007f87e2203868>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87e2203868>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87e2203868>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f8790bde5e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87f523e918>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f05750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110f05730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f09880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87e2203de0>, <W_TypeObject 'GenericAlias' at 0x7f87d6ee0f38>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e20082c0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e20082c0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e20082c0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e20082c0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877da69df0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87e20082c0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87e20082c0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877da69df0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87e20082c0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877da69df0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877da69df0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877da69df0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87f74d2ea8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f3a31a38>
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 0x00007f87a59bd760>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87a59bd760>
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 0x00007f87a671f248>
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 0x00007f87a671f248>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87a671f248>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87a671f248>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87c1d4c820>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87910a3c58>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110fce750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110fce730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110fd2880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87a671f7c0>, <W_TypeObject 'GenericAlias' at 0x7f87d5d99be8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d60e5d00>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d60e5d00>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d60e5d00>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d60e5d00>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b0c8620>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87d60e5d00>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87d60e5d00>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b0c8620>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87d60e5d00>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b0c8620>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b0c8620>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b0c8620>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87c201ba60>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87e0965790>
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 0x00007f87f79f8620>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87f79f8620>
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 0x00007f87c2479e88>
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 0x00007f87c2479e88>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87c2479e88>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87c2479e88>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87f79f9720>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87e271c918>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x111097750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x111097730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11109b880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87f7a08448>, <W_TypeObject 'GenericAlias' at 0x7f87d75f81e0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8770c59f68>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8770c59f68>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8770c59f68>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8770c59f68>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877b354c10>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f8770c59f68>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f8770c59f68>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877b354c10>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f8770c59f68>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877b354c10>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877b354c10>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877b354c10>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d77ab100>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87a7ee40c0>
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 0x00007f87d249f460>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87d249f460>
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 0x00007f87d4fa2c60>
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 0x00007f87d4fa2c60>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87d4fa2c60>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87d4fa2c60>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a1317060>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87b49e7bb0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b18750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110b18730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b1c880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87d4fa31d8>, <W_TypeObject 'GenericAlias' at 0x7f8780960c98>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e175c138>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e175c138>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e175c138>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e175c138>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e6fef10>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87e175c138>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87e175c138>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e6fef10>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87e175c138>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e6fef10>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e6fef10>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e6fef10>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87e1db6bd8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f4e92160>
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 0x00007f87f34f2e20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87f34f2e20>
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 0x00007f87d55d3b40>
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 0x00007f87d55d3b40>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87d55d3b40>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87d55d3b40>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87f34e5c60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d602dc58>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be1750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110be1730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be5880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87d55c6ec8>, <W_TypeObject 'GenericAlias' at 0x7f87d5ec0330>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a6e3d868>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a6e3d868>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a6e3d868>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a6e3d868>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dd871d0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87a6e3d868>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87a6e3d868>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dd871d0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87a6e3d868>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dd871d0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dd871d0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dd871d0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87b4edcd40>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87a7d415b0>
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 0x00007f87b57be7a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b57be7a0>
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 0x00007f8770208e20>
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 0x00007f8770208e20>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f8770208e20>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f8770208e20>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87b57bf960>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d61fb830>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110caa750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110caa730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110cae880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f8770209398>, <W_TypeObject 'GenericAlias' at 0x7f87b716c218>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b605cd08>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b605cd08>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b605cd08>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b605cd08>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5f2640>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87b605cd08>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87b605cd08>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5f2640>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87b605cd08>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5f2640>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5f2640>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5f2640>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87e1cbd6a0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87b58504a8>
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 0x00007f87b7b102a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b7b102a0>
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 0x00007f87f64d59f0>
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 0x00007f87f64d59f0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87f64d59f0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87f64d59f0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87b7b11460>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87b5fc25d0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d73750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110d73730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d77880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87f64d5f68>, <W_TypeObject 'GenericAlias' at 0x7f87f4bdd6a8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f727f0c0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f727f0c0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f727f0c0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f727f0c0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e510260>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87f727f0c0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87f727f0c0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e510260>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87f727f0c0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e510260>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e510260>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e510260>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a69f7970>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f71125e8>
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 0x00007f87a70a46e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87a70a46e0>
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 0x00007f87f6cb69c0>
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 0x00007f87f6cb69c0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87f6cb69c0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87f6cb69c0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a70a59e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87911c3440>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e3c750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110e3c730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e40880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87f6cb6f38>, <W_TypeObject 'GenericAlias' at 0x7f87a5dac800>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b5296368>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b5296368>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b5296368>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b5296368>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e4c7cb0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87b5296368>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87b5296368>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e4c7cb0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87b5296368>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e4c7cb0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e4c7cb0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e4c7cb0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a5a1da60>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87a744cde0>
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 0x00007f87c1d4c6e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87c1d4c6e0>
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 0x00007f87f6d8ec98>
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 0x00007f87f6d8ec98>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87f6d8ec98>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87f6d8ec98>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87c1d4da60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87f6b412f0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f05750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110f05730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f09880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87f6d8f210>, <W_TypeObject 'GenericAlias' at 0x7f87b7c45558>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b5209398>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b5209398>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b5209398>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b5209398>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877df6dfb0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87b5209398>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87b5209398>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877df6dfb0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87b5209398>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877df6dfb0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877df6dfb0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877df6dfb0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f8790fb8020>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87e10e6160>
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 0x00007f87b6631860>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b6631860>
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 0x00007f87b65e5050>
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 0x00007f87b65e5050>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87b65e5050>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87b65e5050>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87500c4ba0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f876009bb08>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110fce750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110fce730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110fd2880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87b65e55c8>, <W_TypeObject 'GenericAlias' at 0x7f87d59352f0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d58d7b40>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d58d7b40>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d58d7b40>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d58d7b40>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e3febb0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87d58d7b40>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87d58d7b40>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e3febb0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87d58d7b40>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e3febb0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e3febb0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e3febb0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87e271ea70>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87a47c4f70>
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 0x00007f87a53b5de0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87a53b5de0>
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 0x00007f87b3fc8800>
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 0x00007f87b3fc8800>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87b3fc8800>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87b3fc8800>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a53cb160>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f8780670db0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b18750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110b18730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b1c880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87b3fc8de8>, <W_TypeObject 'GenericAlias' at 0x7f87e10a7cc8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a4483b08>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a4483b08>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a4483b08>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a4483b08>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877d8eae20>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87a4483b08>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87a4483b08>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877d8eae20>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87a4483b08>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877d8eae20>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877d8eae20>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877d8eae20>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a78c4278>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87e14a49d0>
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 0x00007f87a26c9b60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87a26c9b60>
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 0x00007f87e1a8c218>
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 0x00007f87e1a8c218>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87e1a8c218>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87e1a8c218>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a2707260>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87a6ec5868>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be1750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110be1730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be5880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87e1a8c790>, <W_TypeObject 'GenericAlias' at 0x7f87d4a11408>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d4b7f670>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d4b7f670>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d4b7f670>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d4b7f670>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e0dc2e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87d4b7f670>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87d4b7f670>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e0dc2e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87d4b7f670>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e0dc2e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e0dc2e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e0dc2e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f8790b79100>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87a511eed0>
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 0x00007f87a33a4ba0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87a33a4ba0>
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 0x00007f87b487f9b8>
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 0x00007f87b487f9b8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87b487f9b8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87b487f9b8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87b2136220>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d68012f0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110caa750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110caa730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110cae880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87b48f4058>, <W_TypeObject 'GenericAlias' at 0x7f87e222f4b0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f58d2640>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f58d2640>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f58d2640>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f58d2640>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e131540>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87f58d2640>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87f58d2640>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e131540>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87f58d2640>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e131540>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e131540>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e131540>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a63606b0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87b5066fc0>
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 0x00007f87e1b479a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87e1b479a0>
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 0x00007f87a644dd70>
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 0x00007f87a644dd70>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87a644dd70>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87a644dd70>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87e1b8ef20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87b69ff788>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d73750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110d73730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d77880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87a64223a0>, <W_TypeObject 'GenericAlias' at 0x7f87d53c2330>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b4911718>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b4911718>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b4911718>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b4911718>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877df14ba0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87b4911718>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87b4911718>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877df14ba0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87b4911718>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877df14ba0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877df14ba0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877df14ba0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87f6f57d30>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87a6129268>
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 0x00007f87709127a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87709127a0>
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 0x00007f87d59a51d8>
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 0x00007f87d59a51d8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87d59a51d8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87d59a51d8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f8770913c60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87706c7a98>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e3c750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110e3c730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e40880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87d59a5750>, <W_TypeObject 'GenericAlias' at 0x7f87b7f9cde8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a616c250>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a616c250>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a616c250>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a616c250>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5d8060>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87a616c250>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87a616c250>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5d8060>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87a616c250>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5d8060>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5d8060>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5d8060>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87b52d73d0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87a718ee58>
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 0x00007f8770c7f4e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f8770c7f4e0>
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 0x00007f87a7dbc790>
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 0x00007f87a7dbc790>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87a7dbc790>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87a7dbc790>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f8770c78860>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87714bd9f0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f05750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110f05730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f09880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87a7dbcd08>, <W_TypeObject 'GenericAlias' at 0x7f87f61c88a8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d62fe058>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d62fe058>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d62fe058>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d62fe058>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8573d0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87d62fe058>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87d62fe058>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8573d0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87d62fe058>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8573d0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8573d0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8573d0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87b60a3718>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87d69ee458>
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 0x00007f87e247d560>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87e247d560>
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 0x00007f87e2465a98>
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 0x00007f87e2465a98>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87e2465a98>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87e2465a98>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f8790d32860>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d63be330>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x111160750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x111160730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x111164880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87a63a4058>, <W_TypeObject 'GenericAlias' at 0x7f8790b822c0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5fdce20>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5fdce20>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5fdce20>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5fdce20>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b0f8cc0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5fdce20>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87f5fdce20>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b0f8cc0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87f5fdce20>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b0f8cc0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b0f8cc0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b0f8cc0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87f79d55b0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f3cffad8>
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 0x00007f87b5498da0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b5498da0>
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 0x00007f87b54aebf0>
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 0x00007f87b54aebf0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87b54aebf0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87b54aebf0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87b5499da0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87715eb130>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x111229750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x111229730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11122d880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87b54af168>, <W_TypeObject 'GenericAlias' at 0x7f8770f0bd00>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8770f47a28>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8770f47a28>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8770f47a28>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8770f47a28>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b311840>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f8770f47a28>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f8770f47a28>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b311840>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f8770f47a28>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b311840>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b311840>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b311840>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87c207fd30>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f8780739fb0>
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 0x00007f87b6c23d60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b6c23d60>
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 0x00007f8771f81788>
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 0x00007f8771f81788>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f8771f81788>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f8771f81788>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f8750096f20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87a71bb4e8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b18750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110b18730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b1c880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f8771f81d00>, <W_TypeObject 'GenericAlias' at 0x7f87d3263600>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e0281670>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e0281670>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e0281670>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e0281670>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877d8e3a50>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87e0281670>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87e0281670>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877d8e3a50>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87e0281670>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877d8e3a50>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877d8e3a50>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877d8e3a50>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d7be9718>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87c17e5060>
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 0x00007f87a2876fe0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87a2876fe0>
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 0x00007f87808e5f68>
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 0x00007f87808e5f68>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87808e5f68>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87808e5f68>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87d304a5e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d56494e8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be1750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110be1730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be5880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f8780904528>, <W_TypeObject 'GenericAlias' at 0x7f87b59b7980>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d6ad2480>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d6ad2480>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d6ad2480>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d6ad2480>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5ebbb0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87d6ad2480>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87d6ad2480>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5ebbb0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87d6ad2480>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5ebbb0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5ebbb0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5ebbb0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a4bd6638>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87a4dee5e8>
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 0x00007f87d1db2de0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87d1db2de0>
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 0x00007f87b6aaf638>
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 0x00007f87b6aaf638>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87b6aaf638>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87b6aaf638>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87d1d9a4a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d4a9f6e0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110caa750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110caa730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110cae880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87b6aafbb0>, <W_TypeObject 'GenericAlias' at 0x7f87d6e8f0f8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8791075e18>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8791075e18>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8791075e18>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8791075e18>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f874af192a0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f8791075e18>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f8791075e18>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f874af192a0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f8791075e18>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f874af192a0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f874af192a0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f874af192a0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87b5b1e188>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f8790d91cb8>
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 0x00007f87d745d160>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87d745d160>
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 0x00007f87b50e88e0>
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 0x00007f87b50e88e0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87b50e88e0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87b50e88e0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87d75186a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87b7af9478>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d73750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110d73730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d77880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87b50e8e58>, <W_TypeObject 'GenericAlias' at 0x7f878075e5d0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87c2003e50>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87c2003e50>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87c2003e50>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87c2003e50>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e508070>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87c2003e50>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87c2003e50>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e508070>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87c2003e50>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e508070>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e508070>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e508070>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d6fea098>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87a5c632e0>
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 0x00007f87d5aed460>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87d5aed460>
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 0x00007f87f43450c0>
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 0x00007f87f43450c0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87f43450c0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87f43450c0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87f6a449a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d6864410>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e3c750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110e3c730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e40880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87f4345638>, <W_TypeObject 'GenericAlias' at 0x7f87f45f61a8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f465e218>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f465e218>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f465e218>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f465e218>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e678de0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87f465e218>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87f465e218>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e678de0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87f465e218>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e678de0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e678de0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e678de0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87713e25c0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87b56251c8>
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 0x00007f87b6580b20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b6580b20>
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 0x00007f87f669a3a0>
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 0x00007f87f669a3a0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87f669a3a0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87f669a3a0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87b6581ba0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87a78a5b40>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f05750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110f05730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f09880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87f669a918>, <W_TypeObject 'GenericAlias' at 0x7f87f5fb0ad8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b702d440>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b702d440>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b702d440>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b702d440>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e634130>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87b702d440>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87b702d440>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e634130>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87b702d440>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e634130>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e634130>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e634130>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a7f21c40>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87b7ae00e8>
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 0x00007f87d6ac1b60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87d6ac1b60>
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 0x00007f87c21382c0>
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 0x00007f87c21382c0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87c21382c0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87c21382c0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87d6a5eea0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87f623a8a8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x111097750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x111097730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11109b880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87c2138838>, <W_TypeObject 'GenericAlias' at 0x7f87d7a3b948>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d7a2bc58>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d7a2bc58>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d7a2bc58>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d7a2bc58>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e4dd1a0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87d7a2bc58>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87d7a2bc58>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e4dd1a0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87d7a2bc58>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e4dd1a0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e4dd1a0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e4dd1a0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87f79d5f88>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87a525ee80>
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 0x00007f875009b6a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f875009b6a0>
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 0x00007f87b68ceb48>
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 0x00007f87b68ceb48>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87b68ceb48>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87b68ceb48>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87d5ca8960>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87b67e1050>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x111160750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x111160730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x111164880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87b68cf0c0>, <W_TypeObject 'GenericAlias' at 0x7f87d79fc9f8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f75c9fa0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f75c9fa0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f75c9fa0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f75c9fa0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e489050>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87f75c9fa0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87f75c9fa0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e489050>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87f75c9fa0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e489050>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e489050>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e489050>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87c207e020>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87b424cd68>
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 0x00007f87a5739be0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87a5739be0>
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 0x00007f87704e4800>
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 0x00007f87704e4800>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87704e4800>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87704e4800>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a5773260>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87a22de170>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b18750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110b18730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b1c880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87704e4d78>, <W_TypeObject 'GenericAlias' at 0x7f87a3820b48>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d48173d0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d48173d0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d48173d0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d48173d0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c2529e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87d48173d0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87d48173d0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c2529e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87d48173d0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c2529e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c2529e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c2529e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d7be83e0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f3b4fcb8>
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 0x00007f87b1d4fee0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b1d4fee0>
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 0x00007f87d7287d70>
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 0x00007f87d7287d70>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87d7287d70>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87d7287d70>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87f28c7a60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87f598b5c8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be1750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110be1730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be5880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87d72a0330>, <W_TypeObject 'GenericAlias' at 0x7f87702d5600>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a7363cc8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a7363cc8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a7363cc8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a7363cc8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f87eafdbb70>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87a7363cc8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87a7363cc8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f87eafdbb70>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87a7363cc8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f87eafdbb70>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f87eafdbb70>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f87eafdbb70>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87b461d790>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f4a08660>
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 0x00007f87b2588360>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b2588360>
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 0x00007f87a6924e20>
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 0x00007f87a6924e20>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87a6924e20>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87a6924e20>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87c0c3a560>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87b7f81478>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110caa750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110caa730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110cae880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87a6925398>, <W_TypeObject 'GenericAlias' at 0x7f87b5803d00>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5542bb8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5542bb8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5542bb8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5542bb8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8d8470>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5542bb8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87f5542bb8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8d8470>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87f5542bb8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8d8470>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8d8470>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8d8470>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a70fab60>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87d506eef8>
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 0x00007f87b5a32be0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b5a32be0>
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 0x00007f87f61e50f8>
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 0x00007f87f61e50f8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87f61e50f8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87f61e50f8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87b5a33d60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d50f72f0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d73750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110d73730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d77880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87f61e5670>, <W_TypeObject 'GenericAlias' at 0x7f87d7079280>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a4977c58>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a4977c58>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a4977c58>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a4977c58>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e80eee0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87a4977c58>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87a4977c58>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e80eee0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87a4977c58>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e80eee0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e80eee0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e80eee0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d6908e30>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87d55e8a48>
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 0x00007f87a6d45ee0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87a6d45ee0>
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 0x00007f87a6faeb80>
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 0x00007f87a6faeb80>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87a6faeb80>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87a6faeb80>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a6d57560>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d7500bb8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e3c750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110e3c730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e40880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87a6faf0f8>, <W_TypeObject 'GenericAlias' at 0x7f87a73429c0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87702dce90>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87702dce90>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87702dce90>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87702dce90>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5eee90>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87702dce90>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87702dce90>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5eee90>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87702dce90>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5eee90>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5eee90>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e5eee90>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87f74d2638>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87a5d8eb60>
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 0x00007f87b6b887a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b6b887a0>
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 0x00007f87f4273088>
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 0x00007f87f4273088>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87f4273088>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87f4273088>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87b6b89960>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87e1a5b7f8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f05750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110f05730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f09880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87f4273600>, <W_TypeObject 'GenericAlias' at 0x7f87d5bcc6b0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a5af48e0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a5af48e0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a5af48e0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a5af48e0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dff5a70>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87a5af48e0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87a5af48e0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dff5a70>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87a5af48e0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dff5a70>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dff5a70>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dff5a70>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87f7a19808>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87c1b8ff10>
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 0x00007f87a55775a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87a55775a0>
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 0x00007f87d4eb75c8>
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 0x00007f87d4eb75c8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87d4eb75c8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87d4eb75c8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87b6fe89e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87a554f830>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110fce750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110fce730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110fd2880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87d4eb7b40>, <W_TypeObject 'GenericAlias' at 0x7f87c234a7c8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e2288fa8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e2288fa8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e2288fa8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e2288fa8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876af0c7d0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87e2288fa8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87e2288fa8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876af0c7d0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87e2288fa8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876af0c7d0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876af0c7d0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876af0c7d0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f8771600278>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87b7f01e20>
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 0x00007f87500d7660>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87500d7660>
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 0x00007f87500ffa60>
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 0x00007f87500ffa60>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87500ffa60>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87500ffa60>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87f6bc67e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87f60d2138>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x111097750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x111097730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11109b880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87e1be4020>, <W_TypeObject 'GenericAlias' at 0x7f87600ed788>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8760090d08>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8760090d08>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8760090d08>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8760090d08>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dfaa920>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f8760090d08>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f8760090d08>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dfaa920>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f8760090d08>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dfaa920>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dfaa920>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dfaa920>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87b713c200>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87b4294ae8>
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 0x00007f87a6d0f860>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87a6d0f860>
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 0x00007f87b3933590>
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 0x00007f87b3933590>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87b3933590>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87b3933590>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a7c9cde0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87a35ae2c0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b18750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110b18730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b1c880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87b3933b08>, <W_TypeObject 'GenericAlias' at 0x7f87b443f830>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f3256d78>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f3256d78>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f3256d78>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f3256d78>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877b80dea0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87f3256d78>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87f3256d78>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877b80dea0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87f3256d78>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877b80dea0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877b80dea0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877b80dea0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d7be9718>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87d4c34408>
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 0x00007f87f259cb60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87f259cb60>
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 0x00007f87d6b32758>
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 0x00007f87d6b32758>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87d6b32758>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87d6b32758>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87d25b56e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87a62168e0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be1750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110be1730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be5880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87d6b33018>, <W_TypeObject 'GenericAlias' at 0x7f87701ee8e0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f877034a0c8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f877034a0c8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f877034a0c8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f877034a0c8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877ddf03c0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f877034a0c8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f877034a0c8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877ddf03c0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f877034a0c8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877ddf03c0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877ddf03c0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877ddf03c0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f8790c40f20>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87a4bb5c40>
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 0x00007f87f2548da0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87f2548da0>
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 0x00007f87d6e02790>
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 0x00007f87d6e02790>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87d6e02790>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87d6e02790>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87b29649e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87b67b80c8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110caa750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110caa730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110cae880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87d6e02d40>, <W_TypeObject 'GenericAlias' at 0x7f87b52ea608>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b7b4bd38>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b7b4bd38>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b7b4bd38>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b7b4bd38>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f874af69b50>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87b7b4bd38>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87b7b4bd38>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f874af69b50>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87b7b4bd38>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f874af69b50>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f874af69b50>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f874af69b50>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a71dd358>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f4ef39c0>
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 0x00007f87a6121e60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87a6121e60>
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 0x00007f87e2203130>
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 0x00007f87e2203130>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87e2203130>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87e2203130>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a6163ae0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d6092e20>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d73750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110d73730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d77880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87e22036a8>, <W_TypeObject 'GenericAlias' at 0x7f87d58a13d0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f498de18>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f498de18>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f498de18>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f498de18>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e6e50e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87f498de18>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87f498de18>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e6e50e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87f498de18>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e6e50e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e6e50e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e6e50e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87b7a134c0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87d5d43538>
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 0x00007f87b79a0e60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b79a0e60>
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 0x00007f87715672b8>
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 0x00007f87715672b8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87715672b8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87715672b8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87d5828420>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f877092e288>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e3c750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110e3c730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e40880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f8771567830>, <W_TypeObject 'GenericAlias' at 0x7f87d6f0ade8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a6171ef8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a6171ef8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a6171ef8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a6171ef8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8ad990>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87a6171ef8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87a6171ef8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8ad990>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87a6171ef8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8ad990>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8ad990>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e8ad990>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f8790f67808>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87d7356c00>
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 0x00007f87911dc420>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87911dc420>
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 0x00007f8770b78e20>
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 0x00007f8770b78e20>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f8770b78e20>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f8770b78e20>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87911dd4e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87b622b948>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f05750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110f05730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f09880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f8770b79398>, <W_TypeObject 'GenericAlias' at 0x7f87b513c058>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a5922100>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a5922100>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a5922100>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a5922100>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e4e2510>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87a5922100>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87a5922100>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e4e2510>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87a5922100>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e4e2510>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e4e2510>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e4e2510>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87b6fd29f8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87b5e77bf0>
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 0x00007f87c2330d20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87c2330d20>
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 0x00007f87f75df558>
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 0x00007f87f75df558>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87f75df558>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87f75df558>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87c2331f60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87b7b14720>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110fce750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110fce730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110fd2880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87f75dfad0>, <W_TypeObject 'GenericAlias' at 0x7f87d60c5360>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d60a9248>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d60a9248>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d60a9248>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d60a9248>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876af89480>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87d60a9248>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87d60a9248>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876af89480>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87d60a9248>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876af89480>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876af89480>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876af89480>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d79fff10>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87a73c7808>
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 0x00007f87f5c10660>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87f5c10660>
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 0x00007f87f5c1c020>
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 0x00007f87f5c1c020>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87f5c1c020>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87f5c1c020>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87f5c117a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87a7ce9f68>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x111229750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x111229730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11122d880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87f5c1c598>, <W_TypeObject 'GenericAlias' at 0x7f87d5c842c0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d5ce51d8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d5ce51d8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d5ce51d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d5ce51d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c645f10>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87d5ce51d8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87d5ce51d8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c645f10>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87d5ce51d8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c645f10>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c645f10>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877c645f10>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87505f4728>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87b44004a8>
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 0x00007f87500974e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87500974e0>
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 0x00007f87e106ade8>
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 0x00007f87e106ade8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87e106ade8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87e106ade8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a6d0e8e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87a29cca68>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b18750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110b18730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b1c880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87b3bb7948>, <W_TypeObject 'GenericAlias' at 0x7f87b43edcc8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d4693088>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d4693088>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d4693088>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d4693088>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877db8fe40>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87d4693088>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87d4693088>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877db8fe40>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87d4693088>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877db8fe40>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877db8fe40>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877db8fe40>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87b679af20>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87d3ff71f0>
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 0x00007f87d2625e60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87d2625e60>
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 0x00007f87a5f89a28>
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 0x00007f87a5f89a28>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87a5f89a28>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87a5f89a28>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87c0c013e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87e1977360>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be1750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110be1730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be5880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87b59661e0>, <W_TypeObject 'GenericAlias' at 0x7f87a722e288>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a7300410>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a7300410>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a7300410>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a7300410>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dd99690>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87a7300410>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87a7300410>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dd99690>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87a7300410>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dd99690>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dd99690>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dd99690>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d4f90980>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f3b6bd30>
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 0x00007f87a162c160>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87a162c160>
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 0x00007f87b675a9f8>
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 0x00007f87b675a9f8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87b675a9f8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87b675a9f8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a15d5860>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87a509c0c8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110caa750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110caa730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110cae880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87b675af70>, <W_TypeObject 'GenericAlias' at 0x7f87d531f1d8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f43c1c58>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f43c1c58>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f43c1c58>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f43c1c58>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e00cf70>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87f43c1c58>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87f43c1c58>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e00cf70>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87f43c1c58>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e00cf70>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e00cf70>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e00cf70>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a6f8ca70>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f4b25a38>
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 0x00007f87e1ac34e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87e1ac34e0>
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 0x00007f87f5aaf0c0>
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 0x00007f87f5aaf0c0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87f5aaf0c0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87f5aaf0c0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87b5bd24e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87911c88e0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d73750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110d73730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d77880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87f5aaf7c0>, <W_TypeObject 'GenericAlias' at 0x7f87f5fd9d00>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b6d2d718>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b6d2d718>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b6d2d718>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b6d2d718>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dff23a0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87b6d2d718>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87b6d2d718>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dff23a0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87b6d2d718>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dff23a0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dff23a0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dff23a0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a5a1c278>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87a5ad85c0>
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 0x00007f87709122a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87709122a0>
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 0x00007f87a7021600>
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 0x00007f87a7021600>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87a7021600>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87a7021600>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87709136a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87f517ffa0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e3c750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110e3c730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e40880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87a7021b78>, <W_TypeObject 'GenericAlias' at 0x7f8770bc33d0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5a8d0c0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5a8d0c0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5a8d0c0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5a8d0c0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e56ca10>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87f5a8d0c0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87f5a8d0c0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e56ca10>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87f5a8d0c0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e56ca10>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e56ca10>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e56ca10>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a7f21268>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87e1a0be70>
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 0x00007f87913b2d20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87913b2d20>
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 0x00007f87a4983d70>
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 0x00007f87a4983d70>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87a4983d70>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87a4983d70>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87d6d54320>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87e1ad9210>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f05750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110f05730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f09880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87b6f2e330>, <W_TypeObject 'GenericAlias' at 0x7f87b7311ec0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b555b130>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b555b130>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b555b130>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b555b130>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e653510>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87b555b130>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87b555b130>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e653510>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87b555b130>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e653510>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e653510>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e653510>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87715dc278>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87702684f8>
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 0x00007f8771051760>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f8771051760>
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 0x00007f87a74a9408>
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 0x00007f87a74a9408>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87a74a9408>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87a74a9408>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f8771110ea0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87b606c678>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110fce750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110fce730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110fd2880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87a74a9980>, <W_TypeObject 'GenericAlias' at 0x7f8790d5e7c8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e244c218>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e244c218>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e244c218>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87e244c218>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b377b80>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87e244c218>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87e244c218>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b377b80>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87e244c218>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b377b80>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b377b80>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b377b80>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87600bdda8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87d6dbf6c8>
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 0x00007f87b6711da0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b6711da0>
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 0x00007f87d627c480>
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 0x00007f87d627c480>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87d627c480>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87d627c480>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87d5244fa0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87b5ac6bf0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x111160750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x111160730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x111164880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87d627c9f8>, <W_TypeObject 'GenericAlias' at 0x7f87a7a57948>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a7a43750>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a7a43750>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a7a43750>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a7a43750>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b366f60>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87a7a43750>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87a7a43750>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b366f60>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87a7a43750>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b366f60>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b366f60>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876b366f60>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87f7874b60>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87b41a9218>
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 0x00007f87a57706e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87a57706e0>
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 0x00007f87a73eb7f8>
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 0x00007f87a73eb7f8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87a73eb7f8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87a73eb7f8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a5771960>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87a18e6410>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b18750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110b18730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110b1c880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87a73ebd70>, <W_TypeObject 'GenericAlias' at 0x7f87f32572b8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b42e3590>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b42e3590>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b42e3590>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b42e3590>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dbc2d40>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87b42e3590>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87b42e3590>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dbc2d40>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87b42e3590>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dbc2d40>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dbc2d40>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877dbc2d40>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87b679a6b0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87d4394bd8>
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 0x00007f87a16885a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87a16885a0>
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 0x00007f87f5791018>
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 0x00007f87f5791018>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87f5791018>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87f5791018>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87f25bcaa0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d7286c28>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be1750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110be1730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110be5880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87f5791590>, <W_TypeObject 'GenericAlias' at 0x7f87b5eb3910>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87700b3590>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87700b3590>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87700b3590>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87700b3590>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e079cb0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87700b3590>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87700b3590>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e079cb0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87700b3590>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e079cb0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e079cb0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e079cb0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d51a6db8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87b3ca3ee8>
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 0x00007f87a33a5ea0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87a33a5ea0>
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 0x00007f87913aab48>
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 0x00007f87913aab48>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87913aab48>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87913aab48>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87b268eb60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87a63161e0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110caa750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110caa730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110cae880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87913ab750>, <W_TypeObject 'GenericAlias' at 0x7f87a4b03d38>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f43ee368>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f43ee368>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f43ee368>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f43ee368>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877de1bf60>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87f43ee368>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87f43ee368>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877de1bf60>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87f43ee368>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877de1bf60>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877de1bf60>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877de1bf60>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87a58b8368>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f4939560>
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 0x00007f87b5a339a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b5a339a0>
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 0x00007f877147f2f0>
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 0x00007f877147f2f0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f877147f2f0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f877147f2f0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87b5a70fe0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f878075e8e0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d73750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110d73730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110d77880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f877147f868>, <W_TypeObject 'GenericAlias' at 0x7f8780852838>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d59d8b80>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d59d8b80>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d59d8b80>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87d59d8b80>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f874affd350>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87d59d8b80>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87d59d8b80>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f874affd350>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87d59d8b80>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f874affd350>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f874affd350>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f874affd350>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87d77792e0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87a4fcf7e0>
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 0x00007f87a59569e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87a59569e0>
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 0x00007f87b7b01948>
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 0x00007f87b7b01948>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87b7b01948>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87b7b01948>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87a5957c60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d512e2c0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e3c750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110e3c730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110e40880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87b7b01ec0>, <W_TypeObject 'GenericAlias' at 0x7f87f68f8790>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f68ae100>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f68ae100>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f68ae100>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f68ae100>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e462aa0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87f68ae100>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87f68ae100>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e462aa0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87f68ae100>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e462aa0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e462aa0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e462aa0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87f7a19ad8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87e155da10>
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 0x00007f87e2280fa0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87e2280fa0>
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 0x00007f87d75b8838>
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 0x00007f87d75b8838>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87d75b8838>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87d75b8838>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f8770c7e460>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87b7fbcdb0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f05750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110f05730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110f09880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87d75b9050>, <W_TypeObject 'GenericAlias' at 0x7f87e1ff09c0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a4d853d0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a4d853d0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a4d853d0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87a4d853d0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876afef620>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87a4d853d0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87a4d853d0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876afef620>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87a4d853d0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876afef620>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876afef620>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876afef620>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f875060ecc8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f8780a56598>
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 0x00007f87b7159f20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87b7159f20>
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 0x00007f8770199520>
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 0x00007f8770199520>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f8770199520>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f8770199520>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87b6d03360>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87a5e74bb8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110fce750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x110fce730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x110fd2880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f8770199a98>, <W_TypeObject 'GenericAlias' at 0x7f87f5da8448>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f6052100>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f6052100>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f6052100>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87f6052100>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e3f6dd0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87f6052100>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87f6052100>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e3f6dd0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87f6052100>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e3f6dd0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e3f6dd0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f877e3f6dd0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f87b5abaea8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f87c006ca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87f09547e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f87f06cc9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f87f06cca20>]
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 0x00007f87d7f8bbc8>
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 0x00007f87e17cf920>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f87e17cf920>
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 0x00007f87e1790918>
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 0x00007f87e1790918>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f87e1790918>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f87e1790918>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f87c2260c60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f87d7c3d280>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x111097750>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x111097730>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11109b880>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f87b0ef5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f87e1790e90>, <W_TypeObject 'GenericAlias' at 0x7f87f747f6a8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b65d70c0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b65d70c0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b65d70c0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f87b65d70c0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876af2e540>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f87b65d70c0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f87b65d70c0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876af2e540>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f87b65d70c0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876af2e540>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876af2e540>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f876af2e540>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 ===================================
_________________ AppTestRecompilerPython.test_dlopen_unicode __________________
self = <pypy.interpreter.typedef.W_ObjectObjectUserDictWeakrefable object at 0x00007f87c18845d0>
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-x86_64/usession-py3.12-1420/load_caf\xE9.so: "Cannot load library /tmp/buildbot-x86_64/usession-py3.12-1420/load_caf\xe9.so: dlopen(/tmp/buildbot-x86_64/usession-py3.12-1420/load_caf\xe9.so, 0x0002): tried: '/tmp/buildbot-x86_64/usession-py3.12-1420/load_caf\xe9.so' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/tmp/buildbot-x86_64/usession-py3.12-1420/load_caf\xe9.so' (no such file), '/tmp/buildbot-x86_64/usession-py3.12-1420/load_caf\xe9.so' (no such file), '/private/tmp/buildbot-x86_64/usession-py3.12-1420/load_caf\xe9.so' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/private/tmp/buildbot-x86_64/usession-py3.12-1420/load_caf\xe9.so' (no such file), '/private/tmp/buildbot-x86_64/usession-py3.12-1420/load_caf\xe9.so' (no such file)"
[/Users/matti/build-worker-x86_64/own-macos-x86-64/build/pypy/module/_cffi_backend/test/test_re_python.py:139]:8: OSError
=========================== short test summary info ============================
FAIL module/_cffi_backend/test/test_re_python.py::AppTestRecompilerPython::()::test_dlopen_unicode
======== 1 failed, 330 passed, 13 skipped, 124 error in 1794.35 seconds ========
++ 06:04:59 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 3 items
module/cpyext/test/test_borrow.py EEE
==================================== ERRORS ====================================
_____________ ERROR at setup of AppTestBorrow.test_tuple_borrowing _____________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x00007fa141351bc8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fa12006c9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fa141376060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fa1601049e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fa160104a20>]
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 0x00007fa141376060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fa1601049e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fa160104a20>]
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 0x00007fa14113d7b8>
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 0x00007fa1412f6e20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fa1412f6e20>
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 0x00007fa141353868>
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 0x00007fa141353868>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fa141353868>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fa141353868>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fa121ee1aa0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fa1707a4090>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10db20778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10db20758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10db248a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fa1100a5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fa141353de0>, <W_TypeObject 'GenericAlias' at 0x7fa1219c4020>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa121838c60>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa121838c60>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa121838c60>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa121838c60>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa11830d850>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fa121838c60>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fa121838c60>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa11830d850>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fa121838c60>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa11830d850>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa11830d850>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa11830d850>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fa15249b448>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fa12006c9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fa141376060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fa1601049e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fa160104a20>]
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 0x00007fa141376060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fa1601049e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fa160104a20>]
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 0x00007fa17088c250>
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 0x00007fa17088a460>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fa17088a460>
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 0x00007fa1708864b8>
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 0x00007fa1708864b8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fa1708864b8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fa1708864b8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fa141fb4460>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fa122aebc90>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10dd63778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10dd63758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10dd678a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fa1100a5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fa18256c7c8>, <W_TypeObject 'GenericAlias' at 0x7fa140f16100>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa180b80c28>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa180b80c28>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa180b80c28>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa180b80c28>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa11831ec70>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fa180b80c28>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fa180b80c28>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa11831ec70>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fa180b80c28>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa11831ec70>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa11831ec70>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa11831ec70>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fa140ea66b0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fa12006c9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fa141376060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fa1601049e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fa160104a20>]
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 0x00007fa141376060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fa1601049e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fa160104a20>]
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 0x00007fa151de8d18>
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 0x00007fa182578060>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fa182578060>
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 0x00007fa121d16758>
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 0x00007fa121d16758>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fa121d16758>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fa121d16758>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fa12299a0a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fa141da5360>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10debd778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10debd758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10dec18a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fa1100a5e18>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fa121d16cd0>, <W_TypeObject 'GenericAlias' at 0x7fa12212ea68>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa12210eb10>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa12210eb10>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa12210eb10>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa12210eb10>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa1183b4940>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fa12210eb10>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fa12210eb10>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa1183b4940>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fa12210eb10>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa1183b4940>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa1183b4940>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa1183b4940>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 44.56 seconds ===========================
++ 06:05:09 starting module/cpyext/test/test_bytearrayobject.py [85 started in total]
__ module/cpyext/test/test_arraymodule.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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 18 items
module/cpyext/test/test_arraymodule.py EEEEEEEEEEEEEEEEEE
==================================== ERRORS ====================================
_______________ ERROR at setup of AppTestArrayModule.test_basic ________________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x00007fb909aae2f0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fb9786bc9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb909ac3a38>
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 0x00007fb94973fde0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fb94973fde0>
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 0x00007fb949758a30>
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 0x00007fb949758a30>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fb949758a30>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fb949758a30>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fb909e6ab20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fb958792218>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10dca6768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10dca6748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10dcaa898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fb96876d830>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fb949758fa8>, <W_TypeObject 'GenericAlias' at 0x7fb9093ebfa0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb9182fcad8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb9182fcad8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb9182fcad8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb9182fcad8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb931f6be10>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fb9182fcad8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fb9182fcad8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb931f6be10>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fb9182fcad8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb931f6be10>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb931f6be10>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb931f6be10>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fb949c41e98>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fb9786bc9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb97ae18110>
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 0x00007fb97adf38a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fb97adf38a0>
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 0x00007fb97addfa28>
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 0x00007fb97addfa28>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fb97addfa28>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fb97addfa28>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fb97903a820>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fb909660678>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10deef768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10deef748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10def3898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fb96876d830>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fb97addffa0>, <W_TypeObject 'GenericAlias' at 0x7fb97918de18>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb97908f2b8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb97908f2b8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb97908f2b8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb97908f2b8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902379670>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fb97908f2b8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fb97908f2b8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902379670>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fb97908f2b8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902379670>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902379670>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902379670>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fb9095fa368>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fb9786bc9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb9384aaed0>
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 0x00007fb95887d3a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fb95887d3a0>
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 0x00007fb958882c28>
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 0x00007fb958882c28>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fb958882c28>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fb958882c28>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fb969f1e220>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fb969ed8218>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e03d768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e03d748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e041898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fb96876d830>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fb9588831a0>, <W_TypeObject 'GenericAlias' at 0x7fb90a03e288>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb969e7d0c0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb969e7d0c0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb969e7d0c0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb969e7d0c0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902138d60>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fb969e7d0c0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fb969e7d0c0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902138d60>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fb969e7d0c0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902138d60>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902138d60>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902138d60>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fb97af3a200>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fb9786bc9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb9080b6fe8>
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 0x00007fb96965c6a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fb96965c6a0>
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 0x00007fb908baba98>
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 0x00007fb908baba98>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fb908baba98>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fb908baba98>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fb97a11b860>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fb97a386330>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e168768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e168748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e16c898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fb96876d830>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fb908bd8058>, <W_TypeObject 'GenericAlias' at 0x7fb948f374e8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb9096d0918>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb9096d0918>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb9096d0918>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb9096d0918>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9021a2d40>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fb9096d0918>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fb9096d0918>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9021a2d40>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fb9096d0918>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9021a2d40>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9021a2d40>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9021a2d40>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fb9798d6458>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fb9786bc9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb918320110>
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 0x00007fb90a2df9a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fb90a2df9a0>
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 0x00007fb9497404b8>
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 0x00007fb9497404b8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fb9497404b8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fb9497404b8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fb97b2b0f20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fb97b0a28a8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e231768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e231748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e235898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fb96876d830>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fb949740a30>, <W_TypeObject 'GenericAlias' at 0x7fb96a16e950>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb96a412790>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb96a412790>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb96a412790>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb96a412790>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9022cf910>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fb96a412790>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fb96a412790>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9022cf910>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fb96a412790>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9022cf910>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9022cf910>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9022cf910>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fb97a9eb088>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fb9786bc9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb909b4f8a8>
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 0x00007fb90871c160>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fb90871c160>
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 0x00007fb9692e1e88>
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 0x00007fb9692e1e88>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fb9692e1e88>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fb9692e1e88>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fb9797fd2e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fb908d4ce20>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e106768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e106748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e10a898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fb96876d830>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fb969312448>, <W_TypeObject 'GenericAlias' at 0x7fb9089bc598>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb9096e82f8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb9096e82f8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb9096e82f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb9096e82f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9020bf620>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fb9096e82f8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fb9096e82f8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9020bf620>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fb9096e82f8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9020bf620>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9020bf620>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9020bf620>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fb9095fb448>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fb9786bc9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb95853ea20>
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 0x00007fb949ac8960>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fb949ac8960>
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 0x00007fb97b0bd6e0>
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 0x00007fb97b0bd6e0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fb97b0bd6e0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fb97b0bd6e0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fb949af7420>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fb909ad59f0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e2fa768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e2fa748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e2fe898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fb96876d830>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fb97b0bdc58>, <W_TypeObject 'GenericAlias' at 0x7fb958baa330>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb909e8d558>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb909e8d558>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb909e8d558>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb909e8d558>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb90247d340>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fb909e8d558>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fb909e8d558>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb90247d340>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fb909e8d558>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb90247d340>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb90247d340>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb90247d340>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fb94a53dbc8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fb9786bc9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb9285b06d8>
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 0x00007fb948ddd920>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fb948ddd920>
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 0x00007fb97991cbb8>
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 0x00007fb97991cbb8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fb97991cbb8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fb97991cbb8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fb9692a50e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fb908baa6e8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e083768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e083748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e087898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fb96876d830>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fb97991d168>, <W_TypeObject 'GenericAlias' at 0x7fb908f6d6e0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb908958870>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb908958870>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb908958870>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb908958870>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9738c8ca0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fb908958870>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fb908958870>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9738c8ca0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fb908958870>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9738c8ca0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9738c8ca0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9738c8ca0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fb958839e20>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fb9786bc9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb9083f9038>
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 0x00007fb94985bf20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fb94985bf20>
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 0x00007fb97af68560>
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 0x00007fb97af68560>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fb97af68560>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fb97af68560>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fb96a149520>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fb9497f2fa8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e1ae768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e1ae748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e1b2898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fb96876d830>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fb97af68ad8>, <W_TypeObject 'GenericAlias' at 0x7fb978112bb8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb90956ef38>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb90956ef38>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb90956ef38>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb90956ef38>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902398c10>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fb90956ef38>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fb90956ef38>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902398c10>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fb90956ef38>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902398c10>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902398c10>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902398c10>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fb94a7009f8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fb9786bc9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb978fd8c00>
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 0x00007fb9085c84e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fb9085c84e0>
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 0x00007fb968c1af00>
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 0x00007fb968c1af00>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fb968c1af00>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fb968c1af00>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fb968f8c8e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fb958521210>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e0ca768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e0ca748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e0ce898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fb96876d830>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fb968c1b600>, <W_TypeObject 'GenericAlias' at 0x7fb94941c950>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb908dc17c0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb908dc17c0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb908dc17c0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb908dc17c0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9738e1dd0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fb908dc17c0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fb908dc17c0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9738e1dd0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fb908dc17c0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9738e1dd0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9738e1dd0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9738e1dd0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fb9090c05c0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fb9786bc9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb969dfe520>
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 0x00007fb9092b0be0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fb9092b0be0>
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 0x00007fb94a2c8b80>
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 0x00007fb94a2c8b80>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fb94a2c8b80>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fb94a2c8b80>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fb949a4ea60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fb90ac1bd38>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e3c3768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e3c3748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e3c7898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fb96876d830>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fb94a2f8368>, <W_TypeObject 'GenericAlias' at 0x7fb97ae1cbb8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb90a27c640>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb90a27c640>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb90a27c640>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb90a27c640>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9022fea30>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fb90a27c640>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fb90a27c640>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9022fea30>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fb90a27c640>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9022fea30>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9022fea30>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9022fea30>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fb969fdd880>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fb9786bc9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb979ff0520>
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 0x00007fb90b1b4820>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fb90b1b4820>
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 0x00007fb90b1b6758>
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 0x00007fb90b1b6758>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fb90b1b6758>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fb90b1b6758>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fb90b2f1e20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fb90b332058>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e48c768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e48c748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e490898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fb96876d830>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fb90b1b6cd0>, <W_TypeObject 'GenericAlias' at 0x7fb96a2dfda8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb96a31b1d8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb96a31b1d8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb96a31b1d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb96a31b1d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902335fb0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fb96a31b1d8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fb96a31b1d8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902335fb0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fb96a31b1d8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902335fb0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902335fb0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902335fb0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fb94a701088>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fb9786bc9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb97a57bf38>
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 0x00007fb9490e10a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fb9490e10a0>
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 0x00007fb97ad69f68>
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 0x00007fb97ad69f68>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fb97ad69f68>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fb97ad69f68>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fb979110b60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fb958846218>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e117768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e117748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e11b898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fb96876d830>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fb97ad80528>, <W_TypeObject 'GenericAlias' at 0x7fb949aa7788>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb97b297be8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb97b297be8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb97b297be8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb97b297be8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9021f3830>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fb97b297be8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fb97b297be8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9021f3830>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fb97b297be8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9021f3830>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9021f3830>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9021f3830>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fb908c5e6b0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fb9786bc9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb9083dccc8>
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 0x00007fb92878af20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fb92878af20>
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 0x00007fb97b525ec0>
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 0x00007fb97b525ec0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fb97b525ec0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fb97b525ec0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fb9287d67e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fb90a485398>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e2d9768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e2d9748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e2dd898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fb96876d830>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fb958328480>, <W_TypeObject 'GenericAlias' at 0x7fb97b7228e0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb96a89d910>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb96a89d910>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb96a89d910>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb96a89d910>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb90249adc0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fb96a89d910>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fb96a89d910>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb90249adc0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fb96a89d910>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb90249adc0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb90249adc0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb90249adc0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fb94a18a278>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fb9786bc9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb97b86c890>
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 0x00007fb979c555a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fb979c555a0>
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 0x00007fb90854cc98>
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 0x00007fb90854cc98>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fb90854cc98>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fb90854cc98>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fb948c39de0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fb979030020>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e142768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e142748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e146898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fb96876d830>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fb978ea8bf0>, <W_TypeObject 'GenericAlias' at 0x7fb92855e1e0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb96987bde0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb96987bde0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb96987bde0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb96987bde0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902544620>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fb96987bde0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fb96987bde0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902544620>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fb96987bde0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902544620>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902544620>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902544620>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fb90ae9e908>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fb9786bc9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb918375ad8>
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 0x00007fb969f34760>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fb969f34760>
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 0x00007fb95837f9f0>
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 0x00007fb95837f9f0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fb95837f9f0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fb95837f9f0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fb958ad7b60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fb94a2bfb08>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e555768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e555748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e559898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fb96876d830>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fb9583866e8>, <W_TypeObject 'GenericAlias' at 0x7fb9780b0c28>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb9093828a8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb9093828a8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb9093828a8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb9093828a8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb90238b3e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fb9093828a8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fb9093828a8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb90238b3e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fb9093828a8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb90238b3e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb90238b3e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb90238b3e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fb958a98e30>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fb9786bc9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb908184db8>
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 0x00007fb97b4275a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fb97b4275a0>
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 0x00007fb97b3e8608>
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 0x00007fb97b3e8608>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fb97b3e8608>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fb97b3e8608>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fb90a4c5320>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fb96a684b48>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e61e768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e61e748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e622898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fb96876d830>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fb97b3e8b80>, <W_TypeObject 'GenericAlias' at 0x7fb96ab129c0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb97ba67f30>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb97ba67f30>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb97ba67f30>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb97ba67f30>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9027cbc10>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fb97ba67f30>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fb97ba67f30>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9027cbc10>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fb97ba67f30>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9027cbc10>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9027cbc10>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb9027cbc10>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fb97ae1e908>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fb9786bc9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb90970c8a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb9380fca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb9380fca60>]
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 0x00007fb9586d9948>
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 0x00007fb97a2c5420>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fb97a2c5420>
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 0x00007fb969e50bb8>
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 0x00007fb969e50bb8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fb969e50bb8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fb969e50bb8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fb908835860>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fb9499d5718>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e20c768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e20c748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e210898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fb96876d830>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fb969e51130>, <W_TypeObject 'GenericAlias' at 0x7fb969e8fd00>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb90a115c90>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb90a115c90>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb90a115c90>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb90a115c90>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902074400>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fb90a115c90>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fb90a115c90>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902074400>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fb90a115c90>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902074400>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902074400>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb902074400>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 234.82 seconds ==========================
++ 06:05:43 starting module/cpyext/test/test_bytesobject.py [86 started in total]
__ module/cpyext/test/test_buffer.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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 6 items
module/cpyext/test/test_buffer.py EEEEEE
==================================== ERRORS ====================================
____________ ERROR at setup of AppTestBuffer.test_size_from_format _____________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x00007fbaa8649e98>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fbad006e9c0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fbafa8e58a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fbab81949e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fbab8194a20>]
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 0x00007fbafa8e58a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fbab81949e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fbab8194a20>]
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 0x00007fbab8f1c7f0>
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 0x00007fbab8f87020>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fbab8f87020>
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 0x00007fbab8f18528>
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 0x00007fbab8f18528>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fbab8f18528>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fbab8f18528>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fbad202d7e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fbafad411a0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a04e768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10a04e748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a052898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fbab870a9c0>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fbab8f18aa0>, <W_TypeObject 'GenericAlias' at 0x7fbae9603328>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbae94142c0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbae94142c0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbae94142c0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbae94142c0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba90731710>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fbae94142c0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fbae94142c0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba90731710>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fbae94142c0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba90731710>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba90731710>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba90731710>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fbafb0d6f20>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fbad006e9c0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fbafa8e58a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fbab81949e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fbab8194a20>]
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 0x00007fbafa8e58a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fbab81949e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fbab8194a20>]
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 0x00007fbafaeefb28>
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 0x00007fbae9e89d60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fbae9e89d60>
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 0x00007fbae9eb2720>
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 0x00007fbae9eb2720>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fbae9eb2720>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fbae9eb2720>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fbaa87288e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fbad107d8d8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a291768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10a291748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a295898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fbab870a9c0>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fbae9eb2c98>, <W_TypeObject 'GenericAlias' at 0x7fbaf9739e18>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbab8e1cd08>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbab8e1cd08>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbab8e1cd08>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbab8e1cd08>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba9071db10>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fbab8e1cd08>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fbab8e1cd08>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba9071db10>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fbab8e1cd08>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba9071db10>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba9071db10>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba9071db10>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fbab96f1790>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fbad006e9c0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fbafa8e58a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fbab81949e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fbab8194a20>]
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 0x00007fbafa8e58a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fbab81949e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fbab8194a20>]
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 0x00007fba98491290>
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 0x00007fbad1fd1060>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fbad1fd1060>
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 0x00007fbad1ff2e58>
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 0x00007fbad1ff2e58>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fbad1ff2e58>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fbad1ff2e58>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fbaba1d13e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fbae9cc3f30>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a3ec768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10a3ec748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a3f0898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fbab870a9c0>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fbad1ff33d0>, <W_TypeObject 'GenericAlias' at 0x7fbae9c2e1e0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbad233b7c0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbad233b7c0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbad233b7c0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbad233b7c0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba90b852c0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fbad233b7c0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fbad233b7c0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba90b852c0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fbad233b7c0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba90b852c0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba90b852c0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba90b852c0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fbabadb5b50>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fbad006e9c0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fbafa8e58a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fbab81949e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fbab8194a20>]
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 0x00007fbafa8e58a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fbab81949e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fbab8194a20>]
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 0x00007fbab8743dd0>
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 0x00007fbad0fba820>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fbad0fba820>
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 0x00007fbab8d7f868>
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 0x00007fbab8d7f868>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fbab8d7f868>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fbab8d7f868>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fbaf9786f20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fbafa82a058>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a517768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10a517748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a51b898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fbab870a9c0>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fbab8d7fde0>, <W_TypeObject 'GenericAlias' at 0x7fbab9000020>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbafa59e6b0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbafa59e6b0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbafa59e6b0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbafa59e6b0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba90a352b0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fbafa59e6b0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fbafa59e6b0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba90a352b0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fbafa59e6b0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba90a352b0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba90a352b0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba90a352b0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fbab8f6c020>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fbad006e9c0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fbafa8e58a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fbab81949e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fbab8194a20>]
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 0x00007fbafa8e58a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fbab81949e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fbab8194a20>]
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 0x00007fbafab59380>
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 0x00007fbad1f6ee60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fbad1f6ee60>
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 0x00007fbad1f2ccd0>
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 0x00007fbad1f2ccd0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fbad1f2ccd0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fbad1f2ccd0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fbafb059ea0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fbae9e1e6e8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a5e0768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10a5e0748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a5e4898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fbab870a9c0>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fbad1f2d248>, <W_TypeObject 'GenericAlias' at 0x7fbae9ffd7c0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbab9f1caa0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbab9f1caa0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbab9f1caa0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbab9f1caa0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba90a65e90>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fbab9f1caa0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fbab9f1caa0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba90a65e90>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fbab9f1caa0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba90a65e90>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba90a65e90>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba90a65e90>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fbad28c7088>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fbad006e9c0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fbafa8e58a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fbab81949e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fbab8194a20>]
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 0x00007fbafa8e58a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fbab81949e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fbab8194a20>]
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 0x00007fbafad31718>
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 0x00007fbae90ff6e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fbae90ff6e0>
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 0x00007fbad0f54c28>
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 0x00007fbad0f54c28>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fbad0f54c28>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fbad0f54c28>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fbad10b86e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fbafab4b910>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a4b5768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10a4b5748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a4b9898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fbab870a9c0>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fbad0f551a0>, <W_TypeObject 'GenericAlias' at 0x7fbad1d25bb0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbab9668c60>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbab9668c60>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbab9668c60>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fbab9668c60>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba90d51280>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fbab9668c60>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fbab9668c60>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba90d51280>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fbab9668c60>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba90d51280>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba90d51280>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fba90d51280>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 83.19 seconds ===========================
++ 06:06:48 starting module/cpyext/test/test_capsule.py [87 started in total]
__ module/cpyext/test/test_bytearrayobject.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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 6 items
module/cpyext/test/test_bytearrayobject.py EEEEEE
==================================== ERRORS ====================================
_______________ ERROR at setup of AppTestStringObject.test_basic _______________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x00007f837a357718>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f837819e9c0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f837a2863a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f834806c960>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f834806c9a0>]
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 0x00007f837a2863a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f834806c960>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f834806c9a0>]
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 0x00007f83885e8840>
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 0x00007f837a3811e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f837a3811e0>
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 0x00007f837a37f4b0>
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 0x00007f837a37f4b0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f837a37f4b0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f837a37f4b0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f837a55e120>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f83690e46e8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x109b78768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x109b78748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x109b7c898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f83787d3cc8>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f837a37fa28>, <W_TypeObject 'GenericAlias' at 0x7f837a01e100>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f838836d8d8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f838836d8d8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f838836d8d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f838836d8d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f83627c9e10>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f838836d8d8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f838836d8d8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f83627c9e10>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f838836d8d8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f83627c9e10>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f83627c9e10>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f83627c9e10>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f835aaff808>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f837819e9c0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f837a2863a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f834806c960>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f834806c9a0>]
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 0x00007f837a2863a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f834806c960>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f834806c9a0>]
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 0x00007f8350471998>
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 0x00007f8369ab88a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f8369ab88a0>
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 0x00007f8369ad0250>
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 0x00007f8369ad0250>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f8369ad0250>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f8369ad0250>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f838883e7e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f835ada2720>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x109dbe768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x109dbe748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x109dc2898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f83787d3cc8>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f8369ad07c8>, <W_TypeObject 'GenericAlias' at 0x7f8368597088>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f835852d558>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f835852d558>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f835852d558>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f835852d558>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8332834d60>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f835852d558>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f835852d558>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8332834d60>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f835852d558>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8332834d60>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8332834d60>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8332834d60>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f835a37a188>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f837819e9c0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f837a2863a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f834806c960>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f834806c9a0>]
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 0x00007f837a2863a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f834806c960>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f834806c9a0>]
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 0x00007f835a189808>
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 0x00007f839a3f22a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f839a3f22a0>
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 0x00007f8369ac3440>
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 0x00007f8369ac3440>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f8369ac3440>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f8369ac3440>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f83693f90a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f8399d90fa8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x109f19768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x109f19748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x109f1d898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f83787d3cc8>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f8369ac39b8>, <W_TypeObject 'GenericAlias' at 0x7f8369742608>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8369242f38>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8369242f38>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8369242f38>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8369242f38>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f833270bb60>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f8369242f38>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f8369242f38>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f833270bb60>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f8369242f38>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f833270bb60>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f833270bb60>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f833270bb60>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f835acd2020>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f837819e9c0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f837a2863a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f834806c960>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f834806c9a0>]
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 0x00007f837a2863a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f834806c960>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f834806c9a0>]
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 0x00007f8359a7d128>
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 0x00007f83382ee8e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f83382ee8e0>
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 0x00007f83598e92f0>
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 0x00007f83598e92f0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f83598e92f0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f83598e92f0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f8379cc4620>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f837a08ccd0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a044768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10a044748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a048898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f83787d3cc8>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f83598e9868>, <W_TypeObject 'GenericAlias' at 0x7f835a32a838>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8348153b08>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8348153b08>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8348153b08>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8348153b08>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8332816b30>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f8348153b08>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f8348153b08>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8332816b30>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f8348153b08>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8332816b30>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8332816b30>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8332816b30>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f839a2e6110>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f837819e9c0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f837a2863a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f834806c960>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f834806c9a0>]
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 0x00007f837a2863a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f834806c960>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f834806c9a0>]
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 0x00007f8359def830>
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 0x00007f83505eac20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f83505eac20>
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 0x00007f835a875520>
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 0x00007f835a875520>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f835a875520>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f835a875520>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f839a91f7a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f839a238c98>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a10d768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10a10d748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a111898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f83787d3cc8>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f835a875a98>, <W_TypeObject 'GenericAlias' at 0x7f835afdc250>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f839a5cead8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f839a5cead8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f839a5cead8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f839a5cead8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8332c079a0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f839a5cead8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f839a5cead8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8332c079a0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f839a5cead8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8332c079a0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8332c079a0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8332c079a0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f835b7b9c40>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f837819e9c0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f837a2863a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f834806c960>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f834806c9a0>]
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 0x00007f837a2863a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f834806c960>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f834806c9a0>]
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 0x00007f8388691970>
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 0x00007f83596f1460>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f83596f1460>
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 0x00007f8399a2df68>
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 0x00007f8399a2df68>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f8399a2df68>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f8399a2df68>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f8379c68c60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f8368dda5d0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x109fe2768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x109fe2748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x109fe6898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f83787d3cc8>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f8399a5d910>, <W_TypeObject 'GenericAlias' at 0x7f835a62af70>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f835a70bef8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f835a70bef8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f835a70bef8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f835a70bef8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8332993700>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f835a70bef8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f835a70bef8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8332993700>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f835a70bef8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8332993700>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8332993700>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8332993700>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 81.50 seconds ===========================
++ 06:06:51 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 1 items
module/cpyext/test/test_cell.py E
==================================== ERRORS ====================================
_________________ ERROR at setup of AppTestCell.test_cell_type _________________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x00007fd2018cd538>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fd2201eca30>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fd1e84829e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fd2408d49e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fd2408d4a20>]
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 0x00007fd1e84829e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fd2408d49e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fd2408d4a20>]
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 0x00007fd210448890>
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 0x00007fd210440ee0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fd210440ee0>
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 0x00007fd21044a800>
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 0x00007fd21044a800>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fd21044a800>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fd21044a800>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fd201aa2620>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fd241eebfa0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10c8b7768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10c8b7748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10c8bb898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fd220974e20>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fd21044ad78>, <W_TypeObject 'GenericAlias' at 0x7fd200eee410>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fd22264a598>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fd22264a598>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fd22264a598>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fd22264a598>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fd1d94d19b0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fd22264a598>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fd22264a598>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fd1d94d19b0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fd22264a598>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fd1d94d19b0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fd1d94d19b0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fd1d94d19b0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 17.73 seconds ===========================
++ 06:07:29 starting module/cpyext/test/test_classobject.py [89 started in total]
__ module/cpyext/test/test_capsule.py [87 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 3 items
module/cpyext/test/test_capsule.py EEE
==================================== ERRORS ====================================
_____________ ERROR at setup of AppTestCapsule.test_capsule_import _____________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x00007febf80f6200>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007febf87b49f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007febfab05ba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007febe82c4a20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007febe82c4a60>]
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 0x00007febfab05ba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007febe82c4a20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007febe82c4a60>]
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 0x00007febf80facc8>
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 0x00007febf80dbba0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007febf80dbba0>
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 0x00007febf81021e0>
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 0x00007febf81021e0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007febf81021e0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007febf81021e0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007febaae016a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007febf9c44b10>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10dbc9768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10dbc9748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10dbcd898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007feba83eca30>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007febf8102758>, <W_TypeObject 'GenericAlias' at 0x7febaa416640>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7febf80970c0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7febf80970c0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7febf80970c0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7febf80970c0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7feb907b20f0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7febf80970c0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7febf80970c0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7feb907b20f0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7febf80970c0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7feb907b20f0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7feb907b20f0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7feb907b20f0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007febc941f790>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007febf87b49f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007febfab05ba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007febe82c4a20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007febe82c4a60>]
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 0x00007febfab05ba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007febe82c4a20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007febe82c4a60>]
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 0x00007febc953fd30>
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 0x00007febc952f8e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007febc952f8e0>
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 0x00007febc9563280>
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 0x00007febc9563280>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007febc9563280>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007febc9563280>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007febe82a39a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007febc83b75c8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10de07768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10de07748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10de0b898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007feba83eca30>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007febc95637f8>, <W_TypeObject 'GenericAlias' at 0x7febc87eab48>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7febc8a09da8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7febc8a09da8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7febc8a09da8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7febc8a09da8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7feb908dcf80>>
w_obj = <W_TypeObject 'ellipsis' at 0x7febc8a09da8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7febc8a09da8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7feb908dcf80>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7febc8a09da8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7feb908dcf80>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7feb908dcf80>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7feb908dcf80>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007febfa6ac548>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007febf87b49f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007febfab05ba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007febe82c4a20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007febe82c4a60>]
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 0x00007febfab05ba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007febe82c4a20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007febe82c4a60>]
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 0x00007febfa84c778>
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 0x00007feba063ad20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007feba063ad20>
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 0x00007feba0637210>
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 0x00007feba0637210>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007feba0637210>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007feba0637210>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007febab1d86e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007febe9bc48e0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10df62768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10df62748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10df66898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007feba83eca30>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007feba0637788>, <W_TypeObject 'GenericAlias' at 0x7febab566ec8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7febe9bfb980>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7febe9bfb980>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7febe9bfb980>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7febe9bfb980>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7feb90a81640>>
w_obj = <W_TypeObject 'ellipsis' at 0x7febe9bfb980>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7febe9bfb980>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7feb90a81640>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7febe9bfb980>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7feb90a81640>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7feb90a81640>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7feb90a81640>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 45.01 seconds ===========================
++ 06:07:54 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 2 items
module/cpyext/test/test_classobject.py EE
==================================== ERRORS ====================================
_________ ERROR at setup of AppTestInstanceMethod.test_instancemethod __________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x00007f8bf9656bd8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f8c1821c9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f8c199743a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f8bf8104a20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f8bf8104a60>]
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 0x00007f8c199743a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f8bf8104a20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f8bf8104a60>]
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 0x00007f8bf9663038>
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 0x00007f8bf9653160>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f8bf9653160>
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 0x00007f8bf9664a68>
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 0x00007f8bf9664a68>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f8bf9664a68>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f8bf9664a68>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f8c29ef3a60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f8c2a0963a0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e592768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e592748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e596898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f8c181ea480>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f8bf9664fe0>, <W_TypeObject 'GenericAlias' at 0x7f8c19b2e870>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8c19b5cc98>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8c19b5cc98>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8c19b5cc98>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8c19b5cc98>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8bd0d6c240>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f8c19b5cc98>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f8c19b5cc98>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8bd0d6c240>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f8c19b5cc98>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8bd0d6c240>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8bd0d6c240>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8bd0d6c240>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007f8c3a1f5d30>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007f8c1821c9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f8c199743a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f8bf8104a20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f8bf8104a60>]
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 0x00007f8c199743a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007f8bf8104a20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f8bf8104a60>]
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 0x00007f8bf99ddbc8>
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 0x00007f8c3a332520>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007f8c3a332520>
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 0x00007f8c3a348250>
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 0x00007f8c3a348250>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007f8c3a348250>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007f8c3a348250>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007f8c2a19e620>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007f8bd8254480>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e7dd768>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e7dd748>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e7e1898>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007f8c181ea480>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007f8c3a348aa0>, <W_TypeObject 'GenericAlias' at 0x7f8c084966b0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8c28e69558>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8c28e69558>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8c28e69558>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7f8c28e69558>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8bf07dd440>>
w_obj = <W_TypeObject 'ellipsis' at 0x7f8c28e69558>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7f8c28e69558>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8bf07dd440>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7f8c28e69558>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8bf07dd440>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8bf07dd440>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f8bf07dd440>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 31.42 seconds ===========================
++ 06:08:28 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 3 items
module/cpyext/test/test_codecs.py EEE
==================================== ERRORS ====================================
________________ ERROR at setup of TestCodecs.test_incremental _________________
item = <Function 'test_incremental'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tool/pytest/objspace.py:24: in gettestobjspace
space = maketestobjspace(config)
tool/pytest/objspace.py:34: in maketestobjspace
space = make_objspace(config)
tool/option.py:33: in make_objspace
return StdObjSpace(config)
interpreter/baseobjspace.py:481: in __init__
self.initialize()
objspace/std/objspace.py:118: in initialize
self.setup_builtin_modules()
interpreter/baseobjspace.py:739: in setup_builtin_modules
self.fromcache(State).build_api()
module/cpyext/state.py:128: in build_api
self.api_lib = str(api.build_bridge(self.space))
module/cpyext/api.py:1468: in build_bridge
builder.attach_all(space)
module/cpyext/api.py:1535: in attach_all
attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1497: in attach_recursively
make_ref(space, w_type))
module/cpyext/pyobject.py:510: in make_ref
return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:483: in get_pyobj_and_incref
pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445: in as_pyobj
py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:326: in create_ref
track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:375: in track_reference
w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj
rawrefcount.create_link_pypy(self, py_obj)
../rpython/rlib/rawrefcount.py:187: in create_link_pypy
assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:102: in _ob_link_get
return ob.c_ob_pypy_link
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fe1c39c34c0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7fe22594b500>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fe1ea7b5538>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fe20006c9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fe1ea8d5ee0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fe1e8194a20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fe1e8194a60>]
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 0x00007fe1ea8d5ee0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fe1e8194a20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fe1e8194a60>]
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 0x00007fe1c84dfdd0>
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 0x00007fe20a0688e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fe20a0688e0>
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 0x00007fe22a07df30>
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 0x00007fe22a07df30>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fe22a07df30>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fe22a07df30>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fe21884d320>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fe22a13eb10>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10bfc6778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10bfc6758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10bfca8a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fe1ea17b670>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fe22a0624f0>, <W_TypeObject 'GenericAlias' at 0x7fe209f850c0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fe218766560>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fe218766560>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fe218766560>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fe218766560>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fe1c37e8720>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fe218766560>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fe218766560>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fe1c37e8720>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fe218766560>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fe1c37e8720>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fe1c37e8720>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fe1c37e8720>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 43.68 seconds ===========================
++ 06:08:59 starting module/cpyext/test/test_contextvars.py [92 started in total]
__ module/cpyext/test/test_contextvars.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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 1 items
module/cpyext/test/test_contextvars.py E
==================================== ERRORS ====================================
________________ ERROR at setup of AppTestContext.test_context _________________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x00007fae4972df88>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fae2806c9c0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fae5a2132e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fadf80eca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fadf80eca60>]
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 0x00007fae5a2132e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fadf80eca20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fadf80eca60>]
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 0x00007fae49741268>
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 0x00007fae497112a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fae497112a0>
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 0x00007fae4974af00>
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 0x00007fae4974af00>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fae4974af00>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fae4974af00>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fae3b285ca0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fae494a4f70>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e0a1778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e0a1758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e0a58a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fae48af6598>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fae4974b478>, <W_TypeObject 'GenericAlias' at 0x7fae48f42f70>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fae59f78fa8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fae59f78fa8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fae59f78fa8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fae59f78fa8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fae51f51550>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fae59f78fa8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fae59f78fa8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fae51f51550>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fae59f78fa8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fae51f51550>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fae51f51550>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fae51f51550>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 17.70 seconds ===========================
++ 06:09:37 starting module/cpyext/test/test_cpyext.py [93 started in total]
__ module/cpyext/test/test_complexobject.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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 6 items
module/cpyext/test/test_complexobject.py EEEEEE
==================================== ERRORS ====================================
____________ ERROR at setup of TestComplexObject.test_complexobject ____________
item = <Function 'test_complexobject'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tool/pytest/objspace.py:24: in gettestobjspace
space = maketestobjspace(config)
tool/pytest/objspace.py:34: in maketestobjspace
space = make_objspace(config)
tool/option.py:33: in make_objspace
return StdObjSpace(config)
interpreter/baseobjspace.py:481: in __init__
self.initialize()
objspace/std/objspace.py:118: in initialize
self.setup_builtin_modules()
interpreter/baseobjspace.py:739: in setup_builtin_modules
self.fromcache(State).build_api()
module/cpyext/state.py:128: in build_api
self.api_lib = str(api.build_bridge(self.space))
module/cpyext/api.py:1468: in build_bridge
builder.attach_all(space)
module/cpyext/api.py:1535: in attach_all
attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1497: in attach_recursively
make_ref(space, w_type))
module/cpyext/pyobject.py:510: in make_ref
return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:483: in get_pyobj_and_incref
pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445: in as_pyobj
py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:326: in create_ref
track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:375: in track_reference
w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj
rawrefcount.create_link_pypy(self, py_obj)
../rpython/rlib/rawrefcount.py:187: in create_link_pypy
assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:102: in _ob_link_get
return ob.c_ob_pypy_link
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa468f11500>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fa4a0a93100>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fa4c03149f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fa4b1235fa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fa4c067c9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fa4c067ca20>]
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 0x00007fa4b1235fa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fa4c067c9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fa4c067ca20>]
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 0x00007fa4c1dce020>
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 0x00007fa4b1750060>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fa4b1750060>
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 0x00007fa4d25f37f8>
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 0x00007fa4d25f37f8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fa4d25f37f8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fa4d25f37f8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fa4d270ca60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fa4c24b4a30>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a189778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10a189758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a18d8a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fa4d0829980>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fa4d25f3d70>, <W_TypeObject 'GenericAlias' at 0x7fa4d0829d70>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa4b0372e90>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa4b0372e90>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa4b0372e90>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa4b0372e90>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa4a8f732f0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fa4b0372e90>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fa4b0372e90>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa4a8f732f0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fa4b0372e90>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa4a8f732f0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa4a8f732f0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa4a8f732f0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fa4d163a188>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fa4c03149f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fa4b1235fa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fa4c067c9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fa4c067ca20>]
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 0x00007fa4b1235fa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fa4c067c9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fa4c067ca20>]
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 0x00007fa4b0cade20>
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 0x00007fa4b16e2760>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fa4b16e2760>
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 0x00007fa4b16d0330>
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 0x00007fa4b16d0330>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fa4b16d0330>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fa4b16d0330>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fa4ba8dc860>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fa4b1582f00>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a2d5778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10a2d5758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a2d98a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fa4d0829980>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fa4b16d08a8>, <W_TypeObject 'GenericAlias' at 0x7fa4c14170f8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa4a09f0598>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa4a09f0598>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa4a09f0598>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa4a09f0598>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa468fd5b80>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fa4a09f0598>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fa4a09f0598>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa468fd5b80>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fa4a09f0598>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa468fd5b80>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa468fd5b80>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa468fd5b80>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fa4c24c0980>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fa4c03149f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fa4b1235fa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fa4c067c9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fa4c067ca20>]
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 0x00007fa4b1235fa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fa4c067c9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fa4c067ca20>]
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 0x00007fa4b1353678>
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 0x00007fa4b19597a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fa4b19597a0>
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 0x00007fa4b0db66e8>
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 0x00007fa4b0db66e8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fa4b0db66e8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fa4b0db66e8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fa4b04921e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fa47030b018>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a400778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10a400758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a4048a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fa4d0829980>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fa4b0db6c60>, <W_TypeObject 'GenericAlias' at 0x7fa4d14a7ef8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa4c18bb830>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa4c18bb830>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa4c18bb830>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa4c18bb830>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa4691bf380>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fa4c18bb830>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fa4c18bb830>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa4691bf380>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fa4c18bb830>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa4691bf380>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa4691bf380>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa4691bf380>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fa4c0e88ae8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fa4c03149f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fa4b1235fa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fa4c067c9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fa4c067ca20>]
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 0x00007fa4b1235fa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fa4c067c9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fa4c067ca20>]
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 0x00007fa4d191ab88>
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 0x00007fa4b1882d60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fa4b1882d60>
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 0x00007fa4ba2d8918>
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 0x00007fa4ba2d8918>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fa4ba2d8918>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fa4ba2d8918>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fa4ba579de0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fa4b11ddf68>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a4c9778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10a4c9758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a4cd8a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fa4d0829980>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fa4ba2d8e90>, <W_TypeObject 'GenericAlias' at 0x7fa4c22ae800>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa4c1f76fa8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa4c1f76fa8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa4c1f76fa8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa4c1f76fa8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa46908c3c0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fa4c1f76fa8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fa4c1f76fa8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa46908c3c0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fa4c1f76fa8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa46908c3c0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa46908c3c0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa46908c3c0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fa4b07907a0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fa4c03149f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fa4b1235fa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fa4c067c9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fa4c067ca20>]
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 0x00007fa4b1235fa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fa4c067c9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fa4c067ca20>]
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 0x00007fa4d20e12b8>
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 0x00007fa4c287dae0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fa4c287dae0>
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 0x00007fa4c2880ad8>
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 0x00007fa4c2880ad8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fa4c2880ad8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fa4c2880ad8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fa4b1ca61a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fa4907185d0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a3a2778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10a3a2758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a3a68a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fa4d0829980>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fa4c2881050>, <W_TypeObject 'GenericAlias' at 0x7fa4b06b2100>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa4b09cd1d8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa4b09cd1d8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa4b09cd1d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fa4b09cd1d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa4991d9fe0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fa4b09cd1d8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fa4b09cd1d8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa4991d9fe0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fa4b09cd1d8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa4991d9fe0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa4991d9fe0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa4991d9fe0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 83.19 seconds ===========================
++ 06:10:17 starting module/cpyext/test/test_datetime.py [94 started in total]
__ module/cpyext/test/test_bytesobject.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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 20 items
module/cpyext/test/test_bytesobject.py EEEEEEEEEEEEEEEEEEEE
==================================== ERRORS ====================================
____________ ERROR at setup of AppTestBytesObject.test_bytesobject _____________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x00007fab49430ae8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fab5806a988>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fab492e58e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fab1806c9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fab1806c9e0>]
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 0x00007fab492e58e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fab1806c9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fab1806c9e0>]
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 0x00007fab58b16890>
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 0x00007fab58c65a20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fab58c65a20>
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 0x00007fab58b1cf70>
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 0x00007fab58b1cf70>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fab58b1cf70>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fab58b1cf70>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fab4992b6a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fab49bdac98>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10bd11778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10bd11758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10bd158a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fab382ae678>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fab58b1c170>, <W_TypeObject 'GenericAlias' at 0x7fab7a226fe0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab29e67a60>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab29e67a60>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab29e67a60>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab29e67a60>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab10147010>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fab29e67a60>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fab29e67a60>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab10147010>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fab29e67a60>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab10147010>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab10147010>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab10147010>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fab2ae90728>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fab5806a988>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fab492e58e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fab1806c9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fab1806c9e0>]
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 0x00007fab492e58e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fab1806c9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fab1806c9e0>]
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 0x00007fab387d33d0>
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 0x00007fab7ac70b20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fab7ac70b20>
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 0x00007fab7ac749c0>
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 0x00007fab7ac749c0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fab7ac749c0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fab7ac749c0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fab7ae1d060>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fab7a8e78a0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10bf47778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10bf47758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10bf4b8a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fab382ae678>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fab7ac74f38>, <W_TypeObject 'GenericAlias' at 0x7fab3819f590>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab296d9328>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab296d9328>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab296d9328>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab296d9328>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab87f4d0e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fab296d9328>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fab296d9328>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab87f4d0e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fab296d9328>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab87f4d0e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab87f4d0e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab87f4d0e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fab38416f98>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fab5806a988>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fab492e58e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fab1806c9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fab1806c9e0>]
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 0x00007fab492e58e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fab1806c9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fab1806c9e0>]
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 0x00007fab385fbb50>
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 0x00007fab7adc6260>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fab7adc6260>
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 0x00007fab49906020>
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 0x00007fab49906020>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fab49906020>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fab49906020>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fab2a7c32e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fab2a89a8e0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10c0a2778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10c0a2758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10c0a68a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fab382ae678>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fab49907a60>, <W_TypeObject 'GenericAlias' at 0x7fab2abbeb80>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab2a7b9750>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab2a7b9750>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab2a7b9750>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab2a7b9750>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab104635b0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fab2a7b9750>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fab2a7b9750>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab104635b0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fab2a7b9750>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab104635b0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab104635b0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab104635b0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fab29e426b0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fab5806a988>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fab492e58e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fab1806c9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fab1806c9e0>]
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 0x00007fab492e58e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fab1806c9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fab1806c9e0>]
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 0x00007fab48ed52b8>
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 0x00007fab384205e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fab384205e0>
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 0x00007fab589587c8>
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 0x00007fab589587c8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fab589587c8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fab589587c8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fab79e1e1a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fab58ec7bb0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10c1cd778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10c1cd758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10c1d18a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fab382ae678>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fab58958d40>, <W_TypeObject 'GenericAlias' at 0x7fab58f6d2b8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab7804a608>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab7804a608>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab7804a608>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab7804a608>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab07f57f00>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fab7804a608>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fab7804a608>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab07f57f00>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fab7804a608>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab07f57f00>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab07f57f00>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab07f57f00>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fab494a34c0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fab5806a988>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fab492e58e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fab1806c9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fab1806c9e0>]
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 0x00007fab492e58e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fab1806c9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fab1806c9e0>]
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 0x00007fab4946b560>
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 0x00007fab7b119d20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fab7b119d20>
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 0x00007fab2aef37c0>
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 0x00007fab2aef37c0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fab2aef37c0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fab2aef37c0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fab2b0b1f60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fab595d7280>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10c296778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10c296758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10c29a8a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fab382ae678>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fab2aef3d38>, <W_TypeObject 'GenericAlias' at 0x7fab2b0d5da8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab2a9723d8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab2a9723d8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab2a9723d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab2a9723d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab104aab30>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fab2a9723d8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fab2a9723d8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab104aab30>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fab2a9723d8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab104aab30>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab104aab30>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab104aab30>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fab4a0bc728>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fab5806a988>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fab492e58e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fab1806c9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fab1806c9e0>]
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 0x00007fab492e58e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fab1806c9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fab1806c9e0>]
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 0x00007fab49b69ec0>
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 0x00007fab48af9260>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fab48af9260>
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 0x00007fab79eacf38>
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 0x00007fab79eacf38>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fab79eacf38>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fab79eacf38>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fab6866e5e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fab68805c20>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10c16b778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10c16b758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10c16f8a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fab382ae678>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fab79ead4b0>, <W_TypeObject 'GenericAlias' at 0x7fab7a143a98>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab7a7eab48>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab7a7eab48>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab7a7eab48>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab7a7eab48>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab102da050>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fab7a7eab48>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fab7a7eab48>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab102da050>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fab7a7eab48>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab102da050>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab102da050>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab102da050>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fab794edd30>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fab5806a988>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fab492e58e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fab1806c9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fab1806c9e0>]
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 0x00007fab492e58e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fab1806c9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fab1806c9e0>]
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 0x00007fab58957268>
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 0x00007fab2b0b0760>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fab2b0b0760>
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 0x00007fab7a7451d8>
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 0x00007fab7a7451d8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fab7a7451d8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fab7a7451d8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fab2aa985e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fab498d5210>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10c35f778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10c35f758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10c3638a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fab382ae678>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fab7a745750>, <W_TypeObject 'GenericAlias' at 0x7fab7a9bab10>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab18713590>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab18713590>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab18713590>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab18713590>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab103be390>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fab18713590>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fab18713590>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab103be390>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fab18713590>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab103be390>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab103be390>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab103be390>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fab494fadb8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fab5806a988>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fab492e58e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fab1806c9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fab1806c9e0>]
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 0x00007fab492e58e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fab1806c9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fab1806c9e0>]
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 0x00007fab2a3683b8>
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 0x00007fab78df9a60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fab78df9a60>
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 0x00007fab491939b8>
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 0x00007fab491939b8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fab491939b8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fab491939b8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fab29e211e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fab2a04c720>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10c0fe778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10c0fe758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10c1028a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fab382ae678>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fab49193f30>, <W_TypeObject 'GenericAlias' at 0x7fab689b16a8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab7a8143d8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab7a8143d8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab7a8143d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab7a8143d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab105b73e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fab7a8143d8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fab7a8143d8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab105b73e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fab7a8143d8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab105b73e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab105b73e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab105b73e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fab7a090458>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fab5806a988>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fab492e58e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fab1806c9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fab1806c9e0>]
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 0x00007fab492e58e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fab1806c9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fab1806c9e0>]
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 0x00007fab299b56f0>
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 0x00007fab2b510ea0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fab2b510ea0>
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 0x00007fab7ad8cb48>
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 0x00007fab7ad8cb48>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fab7ad8cb48>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fab7ad8cb48>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fab4a664a20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fab2a5a19b8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10c22a778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10c22a758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10c22e8a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fab382ae678>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fab7ad8d0c0>, <W_TypeObject 'GenericAlias' at 0x7fab59abe368>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab2b535da8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab2b535da8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab2b535da8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab2b535da8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab10527b80>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fab2b535da8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fab2b535da8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab10527b80>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fab2b535da8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab10527b80>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab10527b80>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fab10527b80>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7fab57fab900>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7fab104838b0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7fab77fae620>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7fab07f592f0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7fab101068b0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7fab57fb3f60>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7fab77f5c080>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7fab102f2520>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7fab100398d0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7fab103be9a0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7fab103ba540>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 254.30 seconds ==========================
++ 06:10:18 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 16 items
module/cpyext/test/test_datetime.py EEEEEEEEEEEEEEEE
==================================== ERRORS ====================================
___________________ ERROR at setup of TestDatetime.test_date ___________________
item = <Function 'test_date'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tool/pytest/objspace.py:24: in gettestobjspace
space = maketestobjspace(config)
tool/pytest/objspace.py:34: in maketestobjspace
space = make_objspace(config)
tool/option.py:33: in make_objspace
return StdObjSpace(config)
interpreter/baseobjspace.py:481: in __init__
self.initialize()
objspace/std/objspace.py:118: in initialize
self.setup_builtin_modules()
interpreter/baseobjspace.py:739: in setup_builtin_modules
self.fromcache(State).build_api()
module/cpyext/state.py:128: in build_api
self.api_lib = str(api.build_bridge(self.space))
module/cpyext/api.py:1468: in build_bridge
builder.attach_all(space)
module/cpyext/api.py:1535: in attach_all
attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1497: in attach_recursively
make_ref(space, w_type))
module/cpyext/pyobject.py:510: in make_ref
return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:483: in get_pyobj_and_incref
pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445: in as_pyobj
py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:326: in create_ref
track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:375: in track_reference
w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj
rawrefcount.create_link_pypy(self, py_obj)
../rpython/rlib/rawrefcount.py:187: in create_link_pypy
assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:102: in _ob_link_get
return ob.c_ob_pypy_link
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb817abc930>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7fb816fd4100>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7fb837950550>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7fb817ece440>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7fb817d1f3a0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7fb83789ee50>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7fb817abf2f0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7fb817b9de40>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7fb817e7e670>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fb8602b42f0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fb8380b69c0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb8694aa860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb84808e9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb84808e9e0>]
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 0x00007fb8694aa860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb84808e9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb84808e9e0>]
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 0x00007fb87adb42a0>
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 0x00007fb81a984c20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fb81a984c20>
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 0x00007fb81a988ec8>
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 0x00007fb81a988ec8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fb81a988ec8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fb81a988ec8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fb860abb060>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fb878d17c58>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a082778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10a082758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a0868a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fb879d62d08>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fb81a989440>, <W_TypeObject 'GenericAlias' at 0x7fb8489ada98>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb86918ce20>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb86918ce20>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb86918ce20>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb86918ce20>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb817ba01b0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fb86918ce20>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fb86918ce20>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb817ba01b0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fb86918ce20>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb817ba01b0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb817ba01b0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb817ba01b0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fb8588acb60>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fb8380b69c0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb8694aa860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb84808e9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb84808e9e0>]
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 0x00007fb8694aa860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb84808e9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb84808e9e0>]
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 0x00007fb8694a0c28>
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 0x00007fb87acd8620>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fb87acd8620>
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 0x00007fb81a5be9f8>
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 0x00007fb81a5be9f8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fb81a5be9f8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fb81a5be9f8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fb869be0820>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fb860b22d78>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a214778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10a214758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a2188a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fb879d62d08>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fb81a5bef70>, <W_TypeObject 'GenericAlias' at 0x7fb8583f4a68>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb8198ac100>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb8198ac100>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb8198ac100>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb8198ac100>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb817d4cc30>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fb8198ac100>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fb8198ac100>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb817d4cc30>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fb8198ac100>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb817d4cc30>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb817d4cc30>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb817d4cc30>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fb87b12edb8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fb8380b69c0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb8694aa860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb84808e9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb84808e9e0>]
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 0x00007fb8694aa860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb84808e9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb84808e9e0>]
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 0x00007fb879e7ff10>
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 0x00007fb81a9e4b20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fb81a9e4b20>
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 0x00007fb81a9ed558>
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 0x00007fb81a9ed558>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fb81a9ed558>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fb81a9ed558>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fb81a9e4720>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fb87b53ec60>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a033778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10a033758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a0378a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fb879d62d08>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fb81a9edad0>, <W_TypeObject 'GenericAlias' at 0x7fb8690bf7c0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb8692603d8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb8692603d8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb8692603d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb8692603d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb8179ccec0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fb8692603d8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fb8692603d8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb8179ccec0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fb8692603d8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb8179ccec0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb8179ccec0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb8179ccec0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fb87abeacc8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fb8380b69c0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb8694aa860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb84808e9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb84808e9e0>]
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 0x00007fb8694aa860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb84808e9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb84808e9e0>]
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 0x00007fb8691eb7e0>
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 0x00007fb82871a220>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fb82871a220>
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 0x00007fb8584f8ec8>
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 0x00007fb8584f8ec8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fb8584f8ec8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fb8584f8ec8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fb8588b32e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fb86a261d70>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a214778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10a214758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a2188a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fb879d62d08>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fb8584f9440>, <W_TypeObject 'GenericAlias' at 0x7fb849e03da8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb87b137be8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb87b137be8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb87b137be8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb87b137be8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb8378feae0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fb87b137be8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fb87b137be8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb8378feae0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fb87b137be8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb8378feae0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb8378feae0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb8378feae0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fb86a576c50>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fb8380b69c0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb8694aa860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb84808e9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb84808e9e0>]
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 0x00007fb8694aa860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb84808e9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb84808e9e0>]
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 0x00007fb86090a908>
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 0x00007fb87b3751e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fb87b3751e0>
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 0x00007fb87b382528>
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 0x00007fb87b382528>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fb87b382528>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fb87b382528>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fb87b962060>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fb81a989a60>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a0fd778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10a0fd758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a1018a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fb879d62d08>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fb87b382aa0>, <W_TypeObject 'GenericAlias' at 0x7fb828548950>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb868f83478>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb868f83478>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb868f83478>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb868f83478>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb816fa6f50>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fb868f83478>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fb868f83478>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb816fa6f50>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fb868f83478>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb816fa6f50>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb816fa6f50>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb816fa6f50>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fb848b45538>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fb8380b69c0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb8694aa860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb84808e9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb84808e9e0>]
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 0x00007fb8694aa860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb84808e9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb84808e9e0>]
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 0x00007fb86914c278>
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 0x00007fb86998cf20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fb86998cf20>
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 0x00007fb869ba7c90>
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 0x00007fb869ba7c90>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fb869ba7c90>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fb869ba7c90>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fb81a49c060>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fb81a82adb0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a1c6778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10a1c6758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a1ca8a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fb879d62d08>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fb869bcc250>, <W_TypeObject 'GenericAlias' at 0x7fb849c08480>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb869e283d8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb869e283d8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb869e283d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb869e283d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb817c7c6a0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fb869e283d8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fb869e283d8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb817c7c6a0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fb869e283d8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb817c7c6a0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb817c7c6a0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb817c7c6a0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fb87b952e30>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007fb8380b69c0>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb8694aa860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb84808e9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb84808e9e0>]
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 0x00007fb8694aa860>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007fb84808e9a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007fb84808e9e0>]
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 0x00007fb860404a48>
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 0x00007fb849cf3f20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fb849cf3f20>
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 0x00007fb8699098d8>
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 0x00007fb8699098d8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fb8699098d8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fb8699098d8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fb86a5744e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007fb869fc46e8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a28f778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10a28f758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10a2938a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007fb879d62d08>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fb869909e50>, <W_TypeObject 'GenericAlias' at 0x7fb84a140ec8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb84a13b600>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb84a13b600>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb84a13b600>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fb84a13b600>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb817cc1980>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fb84a13b600>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fb84a13b600>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb817cc1980>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fb84a13b600>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb817cc1980>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb817cc1980>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fb817cc1980>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 210.17 seconds ==========================
++ 06:14:08 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-x86_64/own-macos-x86-64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /Users/matti/build-worker-x86_64/own-macos-x86-64/build/pytest.pyc
rootdir: /Users/matti/build-worker-x86_64/own-macos-x86-64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 19 items
module/cpyext/test/test_dictobject.py EEEEEEEEEEEEEEEEEEE
==================================== ERRORS ====================================
__________________ ERROR at setup of TestDictObject.test_dict __________________
item = <Function 'test_dict'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tool/pytest/objspace.py:24: in gettestobjspace
space = maketestobjspace(config)
tool/pytest/objspace.py:34: in maketestobjspace
space = make_objspace(config)
tool/option.py:33: in make_objspace
return StdObjSpace(config)
interpreter/baseobjspace.py:481: in __init__
self.initialize()
objspace/std/objspace.py:118: in initialize
self.setup_builtin_modules()
interpreter/baseobjspace.py:739: in setup_builtin_modules
self.fromcache(State).build_api()
module/cpyext/state.py:128: in build_api
self.api_lib = str(api.build_bridge(self.space))
module/cpyext/api.py:1468: in build_bridge
builder.attach_all(space)
module/cpyext/api.py:1535: in attach_all
attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1497: in attach_recursively
make_ref(space, w_type))
module/cpyext/pyobject.py:510: in make_ref
return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:483: in get_pyobj_and_incref
pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445: in as_pyobj
py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:326: in create_ref
track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:375: in track_reference
w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj
rawrefcount.create_link_pypy(self, py_obj)
../rpython/rlib/rawrefcount.py:187: in create_link_pypy
assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:102: in _ob_link_get
return ob.c_ob_pypy_link
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faaa1d28e40>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7faae215bbc0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7faaa1a6be20>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7faae206b7d0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7faaa1d990c0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7faaa17c47d0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7faaa1917be0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x7faaa1bf02c0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007faab86d2110>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007faad80ec9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007faad8ca7760>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007faad006c9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007faad006ca20>]
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 0x00007faad8ca7760>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007faad006c9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007faad006ca20>]
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 0x00007faab85c67f0>
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 0x00007faae9a43620>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007faae9a43620>
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 0x00007faae9de01a8>
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 0x00007faae9de01a8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007faae9de01a8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007faae9de01a8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007faad8ba3ce0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007faae9a7a3d8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e655778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e655758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e6598a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007faae93b26b0>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007faae9de0720>, <W_TypeObject 'GenericAlias' at 0x7faafab4abb8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7faac86d4448>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7faac86d4448>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7faac86d4448>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7faac86d4448>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faaa1dea780>>
w_obj = <W_TypeObject 'ellipsis' at 0x7faac86d4448>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7faac86d4448>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faaa1dea780>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7faac86d4448>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faaa1dea780>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faaa1dea780>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faaa1dea780>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007faab8613088>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007faad80ec9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007faad8ca7760>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007faad006c9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007faad006ca20>]
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 0x00007faad8ca7760>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007faad006c9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007faad006ca20>]
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 0x00007faae9afdc68>
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 0x00007fab09d2e7e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fab09d2e7e0>
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 0x00007fab09d3a288>
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 0x00007fab09d3a288>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fab09d3a288>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fab09d3a288>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007faad975aaa0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007faafbae7cc8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e970778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e970758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e9748a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007faae93b26b0>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fab09d3a800>, <W_TypeObject 'GenericAlias' at 0x7faafb60e4f0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab09df94e8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab09df94e8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab09df94e8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7fab09df94e8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faaa1b8e7a0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7fab09df94e8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7fab09df94e8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faaa1b8e7a0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7fab09df94e8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faaa1b8e7a0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faaa1b8e7a0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faaa1b8e7a0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007faafa998f98>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007faad80ec9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007faad8ca7760>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007faad006c9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007faad006ca20>]
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 0x00007faad8ca7760>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007faad006c9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007faad006ca20>]
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 0x00007faafa8f4570>
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 0x00007faad05bd3a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007faad05bd3a0>
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 0x00007faafa280480>
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 0x00007faafa280480>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007faafa280480>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007faafa280480>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007fab093f33a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007faae9acbb78>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e69d778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e69d758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e6a18a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007faae93b26b0>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007faafa280ad8>, <W_TypeObject 'GenericAlias' at 0x7faaeab49e18>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7faac8722640>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7faac8722640>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7faac8722640>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7faac8722640>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faae2130d80>>
w_obj = <W_TypeObject 'ellipsis' at 0x7faac8722640>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7faac8722640>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faae2130d80>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7faac8722640>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faae2130d80>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faae2130d80>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faae2130d80>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007faafacc0bd8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007faad80ec9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007faad8ca7760>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007faad006c9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007faad006ca20>]
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 0x00007faad8ca7760>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007faad006c9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007faad006ca20>]
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 0x00007fab08f09e48>
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 0x00007faad969b1a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007faad969b1a0>
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 0x00007faad94b60c8>
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 0x00007faad94b60c8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007faad94b60c8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007faad94b60c8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007faafbaa6c60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007faaa87f9ad0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e845778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e845758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e8498a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007faae93b26b0>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007faad94b6640>, <W_TypeObject 'GenericAlias' at 0x7faafb8bc0c8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7faafb8ef980>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7faafb8ef980>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7faafb8ef980>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7faafb8ef980>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faaa1bd16f0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7faafb8ef980>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7faafb8ef980>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faaa1bd16f0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7faafb8ef980>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faaa1bd16f0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faaa1bd16f0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faaa1bd16f0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007fab09a6e020>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007faad80ec9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007faad8ca7760>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007faad006c9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007faad006ca20>]
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 0x00007faad8ca7760>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007faad006c9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007faad006ca20>]
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 0x00007fab0a0c4520>
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 0x00007fab0a0fc320>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007fab0a0fc320>
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 0x00007fab0a0f2640>
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 0x00007fab0a0f2640>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007fab0a0f2640>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007fab0a0f2640>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00007faaea7ee120>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00007faaf81f04f0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e6d3778>>, <* <C object Struct _object { c_ob_refcnt, c..._ob_refcnt, c_ob_type } at 0x10e6d3758>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e6d78a8>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00007faae93b26b0>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00007fab0a0f2de8>, <W_TypeObject 'GenericAlias' at 0x7faad86624f0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7faad88869f8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7faad88869f8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7faad88869f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x7faad88869f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faaa1d38cc0>>
w_obj = <W_TypeObject 'ellipsis' at 0x7faad88869f8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x7faad88869f8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faaa1d38cc0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x7faad88869f8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faaa1d38cc0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faaa1d38cc0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faaa1d38cc0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00007faaeb2b8e30>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x00007faad80ec9f8>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007faad8ca7760>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007faad006c9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007faad006ca20>]
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 0x00007faad8ca7760>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00007faad006c9e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007faad006ca20>]
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 0x00007faaf9e32c78>
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 0x00007faafab2fe60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00007faafab2fe60>
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 0x00007faaa88fd248>
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 0x00007faaa88fd248>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00007faaa88fd248>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00007faaa88fd248>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import
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=4224.047086