virt_test/bin/python testrunner/runner.py --logfile=testrun.log --config=pypy/testrunner_cfg.py '--config=~/machine_cfg.py' --root=pypy --timeout=4000
in dir /buildbot/slave/own-linux-aarch64/build (timeout 4000 secs)
watching logfiles {'pytestLog': 'testrun.log'}
argv: ['virt_test/bin/python', 'testrunner/runner.py', '--logfile=testrun.log', '--config=pypy/testrunner_cfg.py', '--config=~/machine_cfg.py', '--root=pypy', '--timeout=4000']
environment:
AUDITWHEEL_ARCH=aarch64
AUDITWHEEL_PLAT=manylinux_2_28_aarch64
AUDITWHEEL_POLICY=manylinux_2_28
DEVTOOLSET_ROOTPATH=/opt/rh/gcc-toolset-14/root
HGDEMANDIMPORT=disable
HOME=/home/buildworker
HOSTNAME=ebdee9f243b1
LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
LC_ALL=en_US.UTF-8
LD_LIBRARY_PATH=/usr/local/lib:/opt/rh/gcc-toolset-14/root/usr/lib64:/opt/rh/gcc-toolset-14/root/usr/lib:/opt/rh/gcc-toolset-14/root/usr/lib64/dyninst:/opt/rh/gcc-toolset-14/root/usr/lib/dyninst
OLDPWD=/buildbot/slave
PATH=/tmp/venv/bin:/opt/clang/bin:/opt/rh/gcc-toolset-14/root/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/pypy2.7-v7.3.22-aarch64/bin
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
PS1=(venv)
PWD=/buildbot/slave/own-linux-aarch64/build
PYPYCHERRYPICK=
PYPY_LOCALBASE=/usr/local
PYPY_MAKE_PORTABLE=1
PYPY_USESSION_KEEP=1
PYTHONPATH=.:
SHLVL=0
SSL_CERT_FILE=/opt/_internal/certs.pem
TERM=xterm
TMPDIR=/tmp/pytest
VIRTUAL_ENV=/tmp/venv
container=podman
using PTY: False
using config pypy/testrunner_cfg.py
using config /home/buildworker/machine_cfg.py
running 4 parallel test workers
setting MAKEFLAGS to ' ' (space)
-- config/test
-- interpreter/astcompiler/test
-- interpreter/pyparser/test
-- interpreter/test
-- module/__builtin__/test
-- module/__pypy__/test
-- module/_abc/test
-- module/_ast/test
-- module/_cffi_backend/test
-- module/_codecs/test
-- module/_collections/test
-- module/_continuation/test
-- module/_cppyy/test
-- module/_csv/test
-- module/_demo/test
-- module/_hpy_universal/test/_vendored
-- module/_hpy_universal/test/pypy
-- module/_io/test
-- module/_jitlog/test
-- module/_locale/test
-- module/_lsprof/test
-- module/_md5/test
-- module/_minimal_curses/test
-- module/_multibytecodec/test
-- module/_multiprocessing/test
-- module/_opcode/test
-- module/_pickle/test
-- module/_pickle_support/test
-- module/_posixsubprocess/test
-- module/_pypyjson/test
-- module/_random/test
-- module/_rawffi/alt/test
-- module/_rawffi/test
-- module/_socket/test
-- module/_sre/test
-- module/_vmprof/test
-- module/_warnings/test
-- module/_weakref/test
-- module/_winreg/test
-- module/array/test
-- module/atexit/test
-- module/binascii/test
-- module/bz2/test
-- module/cmath/test
-- module/cpyext/test/test_api.py
-- module/cpyext/test/test_arraymodule.py
-- module/cpyext/test/test_async_iter.py
-- module/cpyext/test/test_boolobject.py
-- module/cpyext/test/test_borrow.py
-- module/cpyext/test/test_buffer.py
-- module/cpyext/test/test_bytearrayobject.py
-- module/cpyext/test/test_bytesobject.py
-- module/cpyext/test/test_capsule.py
-- module/cpyext/test/test_cell.py
-- module/cpyext/test/test_classobject.py
-- module/cpyext/test/test_codecs.py
-- module/cpyext/test/test_complexobject.py
-- module/cpyext/test/test_contextvars.py
-- module/cpyext/test/test_cpyext.py
-- module/cpyext/test/test_datetime.py
-- module/cpyext/test/test_dictobject.py
-- module/cpyext/test/test_eval.py
-- module/cpyext/test/test_exception.py
-- module/cpyext/test/test_fileobject.py
-- module/cpyext/test/test_floatobject.py
-- module/cpyext/test/test_frameobject.py
-- module/cpyext/test/test_funcobject.py
-- module/cpyext/test/test_genobject.py
-- module/cpyext/test/test_getargs.py
-- module/cpyext/test/test_import.py
-- module/cpyext/test/test_iterator.py
-- module/cpyext/test/test_listobject.py
-- module/cpyext/test/test_longobject.py
-- module/cpyext/test/test_mapping.py
-- module/cpyext/test/test_marshal.py
-- module/cpyext/test/test_memoryobject.py
-- module/cpyext/test/test_methodobject.py
-- module/cpyext/test/test_misc.py
-- module/cpyext/test/test_module.py
-- module/cpyext/test/test_namespaceobject.py
-- module/cpyext/test/test_ndarrayobject.py
-- module/cpyext/test/test_number.py
-- module/cpyext/test/test_object.py
-- module/cpyext/test/test_pyerrors.py
-- module/cpyext/test/test_pyfile.py
-- module/cpyext/test/test_pymem.py
-- module/cpyext/test/test_pysignals.py
-- module/cpyext/test/test_pystate.py
-- module/cpyext/test/test_pystrhex.py
-- module/cpyext/test/test_pystrtod.py
-- module/cpyext/test/test_sequence.py
-- module/cpyext/test/test_setobject.py
-- module/cpyext/test/test_sliceobject.py
-- module/cpyext/test/test_structseq.py
-- module/cpyext/test/test_sysmodule.py
-- module/cpyext/test/test_thread.py
-- module/cpyext/test/test_traceback.py
-- module/cpyext/test/test_translate.py
-- module/cpyext/test/test_tupleobject.py
-- module/cpyext/test/test_typedeallocate.py
-- module/cpyext/test/test_typeobject.py
-- module/cpyext/test/test_unicodeobject.py
-- module/cpyext/test/test_userslots.py
-- module/cpyext/test/test_version.py
-- module/cpyext/test/test_weakref.py
-- module/crypt/test
-- module/errno/test
-- module/exceptions/test
-- module/faulthandler/test
-- module/fcntl/test
-- module/gc/test
-- module/imp/test
-- module/itertools/test
-- module/marshal/test
-- module/math/test
-- module/micronumpy/test
-- module/mmap/test
-- module/operator/test
-- module/posix/test
-- module/pwd/test
-- module/pyexpat/test
-- module/pypyjit/test
-- module/select/test
-- module/signal/test
-- module/struct/test
-- module/sys/test
-- module/termios/test
-- module/test_lib_pypy
-- module/thread/test
-- module/time/test
-- module/token/test
-- module/unicodedata/test
-- module/zipimport/test
-- module/zlib/test
-- objspace/fake/test
-- objspace/std/test
-- objspace/test
-- sandbox/test
-- tool/bench/test
-- tool/memusage/test
-- tool/pytest/fake_pytest/test
-- tool/pytest/test
-- tool/release/test
-- tool/test
-- total: 144 to run
++ 02:29:18 starting config/test [1 started in total]
++ 02:29:18 starting interpreter/astcompiler/test [2 started in total]
++ 02:29:18 starting interpreter/pyparser/test [3 started in total]
++ 02:29:18 starting interpreter/test [4 started in total]
__ config/test [1 done in total, somefailed=False] ____________________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 162 items / 1 skipped
config/test/test_pypyoption.py ..................................................................................................................................................................
==================== 162 passed, 1 skipped in 11.52 seconds ====================
++ 02:29:33 starting module/__builtin__/test [5 started in total]
__ interpreter/pyparser/test [2 done in total, somefailed=False] ______________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 77.43 seconds ==========================
++ 02:30:38 starting module/__pypy__/test [6 started in total]
__ module/__builtin__/test [3 done in total, somefailed=False] ________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 139.84 seconds ====================
++ 02:31:58 starting module/_abc/test [7 started in total]
__ module/__pypy__/test [4 done in total, somefailed=False] ___________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 95.79 seconds =====================
++ 02:32:20 starting module/_ast/test [8 started in total]
__ module/_abc/test [5 done in total, somefailed=False] _______________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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.46 seconds ===========================
++ 02:32:42 starting module/_cffi_backend/test [9 started in total]
__ interpreter/astcompiler/test [6 done in total, somefailed=False] ___________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.py
rootdir: /buildbot/slave/own-linux-aarch64/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 267.65 seconds =========================
++ 02:33:53 starting module/_codecs/test [10 started in total]
__ module/_ast/test [7 done in total, somefailed=False] _______________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 127.09 seconds ==========================
++ 02:34:31 starting module/_collections/test [11 started in total]
__ module/_collections/test [8 done in total, somefailed=False] _______________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 89.28 seconds ==========================
++ 02:36:05 starting module/_continuation/test [12 started in total]
__ module/_codecs/test [9 done in total, somefailed=False] ____________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 99 items
module/_codecs/test/apptest_codecs.py ..
module/_codecs/test/test_codecs.py .....................sss...........................................................s......
module/_codecs/test/test_locale.py ...ss.
module/_codecs/test/test_ztranslation.py .
==================== 93 passed, 6 skipped in 195.72 seconds ====================
++ 02:37:16 starting module/_cppyy/test [13 started in total]
__ module/_cppyy/test [10 done in total, somefailed=False] ____________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 0 items
========================= no tests ran in 0.01 seconds =========================
++ 02:37:18 starting module/_csv/test [14 started in total]
__ module/_continuation/test [11 done in total, somefailed=False] _____________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 86.19 seconds =====================
++ 02:37:40 starting module/_demo/test [15 started in total]
__ module/_demo/test [12 done in total, somefailed=False] _____________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 29.81 seconds ===========================
++ 02:38:12 starting module/_hpy_universal/test/_vendored [16 started in total]
__ module/_hpy_universal/test/_vendored [13 done in total, somefailed=True] ___
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__
INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module>
INTERNALERROR> from pypy.module.cpyext import api
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 02:38:15 starting module/_hpy_universal/test/pypy [17 started in total]
__ module/_hpy_universal/test/pypy [14 done in total, somefailed=True] ________
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/_pytest/main.py", line 109, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__
INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart
INTERNALERROR> from pypy.module._hpy_universal.test import support as _support
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module>
INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module>
INTERNALERROR> from pypy.module.cpyext import api
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/pypy/module/cpyext/api.py", line 29, in <module>
INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/pypy/interpreter/generator.py", line 3, in <module>
INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/pypy/interpreter/pyopcode.py", line 15, in <module>
INTERNALERROR> from pypy.interpreter import (
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/pypy/interpreter/pyframe.py", line 22, in <module>
INTERNALERROR> from pypy.interpreter.pymonitoring import (
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/pypy/interpreter/pymonitoring.py", line 5, in <module>
INTERNALERROR> from pypy.interpreter.typedef import TypeDef
INTERNALERROR> File "/buildbot/slave/own-linux-aarch64/build/pypy/interpreter/typedef.py", line 572, in <module>
INTERNALERROR> from pypy.interpreter.pyframe import PyFrame
INTERNALERROR> ImportError: cannot import name 'PyFrame'
++ 02:38:17 starting module/_io/test [18 started in total]
__ module/_csv/test [15 done in total, somefailed=False] ______________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 80.92 seconds ==========================
++ 02:38:45 starting module/_jitlog/test [19 started in total]
__ module/_jitlog/test [16 done in total, somefailed=False] ___________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 1 items
module/_jitlog/test/test__jitlog.py .
========================== 1 passed in 22.59 seconds ===========================
++ 02:39:09 starting module/_locale/test [20 started in total]
__ module/_locale/test [17 done in total, somefailed=False] ___________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 15 items
module/_locale/test/test_locale.py sssssssssssssss
========================= 15 skipped in 16.00 seconds ==========================
++ 02:39:26 starting module/_lsprof/test [21 started in total]
__ module/_lsprof/test [18 done in total, somefailed=False] ___________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 6 items
module/_lsprof/test/test_cprofile.py ......
========================== 6 passed in 18.38 seconds ===========================
++ 02:39:47 starting module/_md5/test [22 started in total]
__ module/_md5/test [19 done in total, somefailed=False] ______________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 8 items
module/_md5/test/test_md5.py ........
========================== 8 passed in 15.99 seconds ===========================
++ 02:40:04 starting module/_minimal_curses/test [23 started in total]
__ module/_minimal_curses/test [20 done in total, somefailed=False] ___________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 6 items
module/_minimal_curses/test/test_curses.py ......
========================== 6 passed in 120.53 seconds ==========================
++ 02:42:07 starting module/_multibytecodec/test [24 started in total]
__ module/_multibytecodec/test [21 done in total, somefailed=False] ___________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 70.51 seconds =====================
++ 02:43:20 starting module/_multiprocessing/test [25 started in total]
__ module/_io/test [22 done in total, somefailed=False] _______________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 380.42 seconds ====================
++ 02:44:40 starting module/_opcode/test [26 started in total]
__ interpreter/test [23 done in total, somefailed=False] ______________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
PYTHON3: /usr/local/bin/python3.12
(Version 3.12.13 (main, May 13 2026, 03:52:05) [GCC 14.2.1 20250110 (Red Hat 14.2.1-11)])
rootdir: /buildbot/slave/own-linux-aarch64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 1389 items
interpreter/test/apptest_annotations.py ..........................
interpreter/test/apptest_annotations_string.py ......
interpreter/test/apptest_buffer.py .......
interpreter/test/apptest_class.py ................
interpreter/test/apptest_compiler.py ....................................................................................................
interpreter/test/apptest_coroutine.py ..........................................................
interpreter/test/apptest_descrtypecheck.py ..
interpreter/test/apptest_exceptions.py ..........................
interpreter/test/apptest_exctable_dis.py .........
interpreter/test/apptest_exec.py .........................
interpreter/test/apptest_extcall.py .....
interpreter/test/apptest_function.py .....................................s.......................................................
interpreter/test/apptest_generator.py ...................................................................
interpreter/test/apptest_nestedscope.py ..................
interpreter/test/apptest_pep695.py ...............................
interpreter/test/apptest_pycode.py ....
interpreter/test/apptest_pyframe.py ................................................................
interpreter/test/apptest_raise.py ......................................................
interpreter/test/apptest_settrace_jump.py .
interpreter/test/apptest_syntax.py ....................................
interpreter/test/apptest_sys_settrace.py ..............................................................................................................................................
interpreter/test/apptest_traceback.py ........
interpreter/test/apptest_unraisable.py ....
interpreter/test/apptest_with_leak.py .........
interpreter/test/test_app_main.py ..................s..s....................s...s.......................s....x.s...s..........
interpreter/test/test_appinterp.py .............
interpreter/test/test_argument.py ................................................
interpreter/test/test_buffer.py ...
interpreter/test/test_cellfamily.py .......
interpreter/test/test_code.py ............
interpreter/test/test_compiler.py .........
interpreter/test/test_error.py ..............
interpreter/test/test_exceptcomp.py .........
interpreter/test/test_executioncontext.py ................
interpreter/test/test_extmodules.py .
interpreter/test/test_fsencode.py ...
interpreter/test/test_function.py .............
interpreter/test/test_gateway.py .........................................ss.........................
interpreter/test/test_generator.py .
interpreter/test/test_interpreter.py .................................................
interpreter/test/test_location.py ..........
interpreter/test/test_main.py .....
interpreter/test/test_mixedmodule.py ......
interpreter/test/test_module.py ..................
interpreter/test/test_monitoring.py .......
interpreter/test/test_objspace.py .............................................
interpreter/test/test_pycode.py ..
interpreter/test/test_pyframe.py ................................
interpreter/test/test_reverse_debugging.py ..
interpreter/test/test_special.py ...
interpreter/test/test_syntax.py .....................
interpreter/test/test_targetpypy.py ..
interpreter/test/test_typedef.py ...................
interpreter/test/test_unicodehelper.py ..........
interpreter/test/test_zpy.py ........
interpreter/test/test_zzpickle_and_slow.py s.....s..s..sss........ss...s.
============= 1369 passed, 19 skipped, 1 xfailed in 938.51 seconds =============
++ 02:45:03 starting module/_pickle/test [27 started in total]
__ module/_opcode/test [24 done in total, somefailed=False] ___________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 5 items
module/_opcode/test/apptest_opcode.py .....
========================== 5 passed in 21.43 seconds ===========================
++ 02:45:04 starting module/_pickle_support/test [28 started in total]
__ module/_pickle_support/test [25 done in total, somefailed=False] ___________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 1 items
module/_pickle_support/test/apptest__pickle_support.py .
========================== 1 passed in 15.18 seconds ===========================
++ 02:45:21 starting module/_posixsubprocess/test [29 started in total]
__ module/_multiprocessing/test [26 done in total, somefailed=False] __________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 13 items
module/_multiprocessing/test/test_interp_semaphore.py .
module/_multiprocessing/test/test_semaphore.py ..........
module/_multiprocessing/test/test_win32.py s
module/_multiprocessing/test/test_ztranslation.py .
==================== 12 passed, 1 skipped in 138.52 seconds ====================
++ 02:45:45 starting module/_pypyjson/test [30 started in total]
__ module/_pypyjson/test [27 done in total, somefailed=False] _________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 54 items / 1 skipped
module/_pypyjson/test/apptest__pypyjson.py ..........
module/_pypyjson/test/test__pypyjson.py ............................................
==================== 54 passed, 1 skipped in 75.56 seconds =====================
++ 02:47:05 starting module/_random/test [31 started in total]
__ module/_posixsubprocess/test [28 done in total, somefailed=False] __________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 10 items
module/_posixsubprocess/test/apptest_subprocess.py .........
module/_posixsubprocess/test/test_ztranslation.py .
========================= 10 passed in 152.91 seconds ==========================
++ 02:48:00 starting module/_rawffi/alt/test [32 started in total]
__ module/_random/test [29 done in total, somefailed=False] ___________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 50.45 seconds ==========================
++ 02:48:04 starting module/_rawffi/test [33 started in total]
__ module/_pickle/test [30 done in total, somefailed=False] ___________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 194.96 seconds ====================
++ 02:48:26 starting module/_socket/test [34 started in total]
__ module/_rawffi/alt/test [31 done in total, somefailed=False] _______________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 34.40 seconds =====================
++ 02:48:38 starting module/_sre/test [35 started in total]
__ module/_rawffi/test [32 done in total, somefailed=False] ___________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 174.56 seconds ====================
n: 2
Arg 0: 3
Arg 1: 15
++ 02:51:04 starting module/_vmprof/test [36 started in total]
__ module/_sre/test [33 done in total, somefailed=False] ______________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 163 items
module/_sre/test/apptest_sre.py ................................................................................s.s......................
module/_sre/test/test_app_sre.py ..............................
module/_sre/test/test_sre_buf.py ............................
=================== 161 passed, 2 skipped in 162.19 seconds ====================
++ 02:51:25 starting module/_warnings/test [37 started in total]
__ module/_vmprof/test [34 done in total, somefailed=False] ___________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 52.95 seconds =====================
++ 02:52:03 starting module/_weakref/test [38 started in total]
__ module/_warnings/test [35 done in total, somefailed=False] _________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 45.68 seconds =====================
++ 02:52:16 starting module/_winreg/test [39 started in total]
__ module/_winreg/test [36 done in total, somefailed=False] ___________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 0 items / 1 skipped
========================== 1 skipped in 0.12 seconds ===========================
++ 02:52:18 starting module/array/test [40 started in total]
__ module/_cffi_backend/test [37 done in total, somefailed=True] ______________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 468 items
module/_cffi_backend/test/test_c.py ....................................................................................s....................................................s.....s.......................s.............................s........................s......
module/_cffi_backend/test/test_fastpath.py ..................
module/_cffi_backend/test/test_ffi_obj.py ...............................................
module/_cffi_backend/test/test_file.py s..
module/_cffi_backend/test/test_parse_c_type.py ..............s...
module/_cffi_backend/test/test_re_python.py ....................
module/_cffi_backend/test/test_recompiler.py EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
module/_cffi_backend/test/test_unicode_literals.py .......
module/_cffi_backend/test/test_wchar_helper.py .
module/_cffi_backend/test/test_ztranslation.py s
==================================== ERRORS ====================================
______________ ERROR at setup of AppTestRecompiler.test_math_sin _______________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000000004175aa70>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000041835510>
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 0x00000000384db260>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000384db260>
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 0x00000000417b00c8>
key = (((True, True, True, False, False, 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 0x00000000417b00c8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000417b00c8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000417b00c8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000422c91e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000423dcc28>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000417b0e20>, <W_TypeObject 'GenericAlias' at 0x4357def8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x43b16aa0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x43b16aa0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x43b16aa0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x43b16aa0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43914fe0>>
w_obj = <W_TypeObject 'ellipsis' at 0x43b16aa0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x43b16aa0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43914fe0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x43b16aa0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43914fe0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43914fe0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43914fe0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000044c56890>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000045524700>
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 0x000000004549dd60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004549dd60>
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 0x00000000454cad40>
key = (((True, True, True, False, False, 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 0x00000000454cad40>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000454cad40>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000454cad40>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000456b5da0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000045957718>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000454cb2b8>, <W_TypeObject 'GenericAlias' at 0x45d251a0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x45da3478>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x45da3478>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x45da3478>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x45da3478>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45d85c80>>
w_obj = <W_TypeObject 'ellipsis' at 0x45da3478>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x45da3478>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45d85c80>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x45da3478>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45d85c80>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45d85c80>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45d85c80>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000046b9d970>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x00000000475bd5b0>
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 0x000000004753eee0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004753eee0>
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 0x00000000475c2058>
key = (((True, True, True, False, False, 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 0x00000000475c2058>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000475c2058>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000475c2058>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004773f3a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000478c1980>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000475c25d0>, <W_TypeObject 'GenericAlias' at 0x47c56fa8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47ce2250>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47ce2250>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47ce2250>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47ce2250>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47c294e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x47ce2250>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x47ce2250>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47c294e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x47ce2250>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47c294e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47c294e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47c294e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000048f356a0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000049987880>
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 0x0000000049916620>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000049916620>
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 0x000000004991b050>
key = (((True, True, True, False, False, 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 0x000000004991b050>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004991b050>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004991b050>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000049c126a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000049d7c6e8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000004991b5c8>, <W_TypeObject 'GenericAlias' at 0x4a044bf0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a0f9168>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a0f9168>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a0f9168>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a0f9168>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4a0b61c0>>
w_obj = <W_TypeObject 'ellipsis' at 0x4a0f9168>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4a0f9168>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4a0b61c0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4a0f9168>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4a0b61c0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4a0b61c0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4a0b61c0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004af64890>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004b93dec0>
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 0x000000004b9327e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004b9327e0>
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 0x000000004b939210>
key = (((True, True, True, False, False, 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 0x000000004b939210>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004b939210>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004b939210>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004bb6c0e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004bd020c8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000004b939788>, <W_TypeObject 'GenericAlias' at 0x4c05c288>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4c108ad8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4c108ad8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4c108ad8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4c108ad8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4c06be10>>
w_obj = <W_TypeObject 'ellipsis' at 0x4c108ad8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4c108ad8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4c06be10>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4c108ad8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4c06be10>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4c06be10>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4c06be10>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004d2b2cc8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004d7d65e8>
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 0x000000004d7738a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004d7738a0>
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 0x000000004d78d788>
key = (((True, True, True, False, False, 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 0x000000004d78d788>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004d78d788>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004d78d788>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004d9a8b60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004dbce560>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004d78dd00>, <W_TypeObject 'GenericAlias' at 0x4dee57f8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4dfccaa0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4dfccaa0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4dfccaa0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4dfccaa0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4deebdc0>>
w_obj = <W_TypeObject 'ellipsis' at 0x4dfccaa0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4dfccaa0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4deebdc0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4dfccaa0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4deebdc0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4deebdc0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4deebdc0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004ec49358>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004f5b5f88>
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 0x000000004f6ca460>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004f6ca460>
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 0x000000004f6c8e90>
key = (((True, True, True, False, False, 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 0x000000004f6c8e90>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004f6c8e90>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004f6c8e90>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004f6cbe60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004f9f4448>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000004f6c9408>, <W_TypeObject 'GenericAlias' at 0x4fccc800>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4fd09600>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4fd09600>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4fd09600>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4fd09600>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4fd62fb0>>
w_obj = <W_TypeObject 'ellipsis' at 0x4fd09600>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4fd09600>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4fd62fb0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4fd09600>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4fd62fb0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4fd62fb0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4fd62fb0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x00000000507ef5b0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x00000000401384f8>
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 0x0000000033e392e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000033e392e0>
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 0x00000000433448e0>
key = (((True, True, True, False, False, 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 0x00000000433448e0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000433448e0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000433448e0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000003a2d4c60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000043d1d408>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000043344e58>, <W_TypeObject 'GenericAlias' at 0x47b51948>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47cb79b8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47cb79b8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47cb79b8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47cb79b8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3c7e62b0>>
w_obj = <W_TypeObject 'ellipsis' at 0x47cb79b8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x47cb79b8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3c7e62b0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x47cb79b8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3c7e62b0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3c7e62b0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3c7e62b0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x00000000456f1a60>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004264af98>
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 0x000000004f735d20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004f735d20>
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 0x000000004f74a528>
key = (((True, True, True, False, False, 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 0x000000004f74a528>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004f74a528>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004f74a528>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004f7534a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004782a720>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004f74aaa0>, <W_TypeObject 'GenericAlias' at 0x4661b600>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x49f9dd00>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x49f9dd00>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x49f9dd00>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x49f9dd00>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d317af0>>
w_obj = <W_TypeObject 'ellipsis' at 0x49f9dd00>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x49f9dd00>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d317af0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x49f9dd00>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d317af0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d317af0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d317af0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x00000000478c7790>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x00000000454ccc28>
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 0x0000000046d515a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000046d515a0>
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 0x0000000041728c98>
key = (((True, True, True, False, False, 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 0x0000000041728c98>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000041728c98>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000041728c98>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000479a2960>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000449c3558>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000041729210>, <W_TypeObject 'GenericAlias' at 0x41ca4448>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x412b77f8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x412b77f8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x412b77f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x412b77f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4a0b2430>>
w_obj = <W_TypeObject 'ellipsis' at 0x412b77f8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x412b77f8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4a0b2430>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x412b77f8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4a0b2430>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4a0b2430>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4a0b2430>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004af65808>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000049b64ea8>
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 0x000000004e655c60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004e655c60>
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 0x000000004e5f1328>
key = (((True, True, True, False, False, 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 0x000000004e5f1328>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004e5f1328>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004e5f1328>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004b0716a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000048a24c60>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004e5f18a0>, <W_TypeObject 'GenericAlias' at 0x4ea701a8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4ea8c758>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4ea8c758>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4ea8c758>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4ea8c758>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x459391a0>>
w_obj = <W_TypeObject 'ellipsis' at 0x4ea8c758>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4ea8c758>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x459391a0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4ea8c758>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x459391a0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x459391a0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x459391a0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004db36c50>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004dfcf1a0>
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 0x000000004e34e5e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004e34e5e0>
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 0x000000004f13db08>
key = (((True, True, True, False, False, 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 0x000000004f13db08>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004f13db08>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004f13db08>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004aaf4820>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004aad5750>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000004e3880c8>, <W_TypeObject 'GenericAlias' at 0x4e5a67c8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a5cdbe8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a5cdbe8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a5cdbe8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a5cdbe8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3f26f7e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x4a5cdbe8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4a5cdbe8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3f26f7e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4a5cdbe8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3f26f7e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3f26f7e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3f26f7e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004b1ea188>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004a71c228>
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 0x000000004a71e020>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004a71e020>
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 0x000000004b1c96a8>
key = (((True, True, True, False, False, 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 0x000000004b1c96a8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004b1c96a8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004b1c96a8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004a71f4a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004ce05670>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004b1c9c20>, <W_TypeObject 'GenericAlias' at 0x4b84e800>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x496a18a0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x496a18a0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x496a18a0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x496a18a0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3ecd4840>>
w_obj = <W_TypeObject 'ellipsis' at 0x496a18a0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x496a18a0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3ecd4840>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x496a18a0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3ecd4840>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3ecd4840>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3ecd4840>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004c575c40>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004b7462c8>
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 0x000000004b740620>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004b740620>
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 0x000000004b7489f8>
key = (((True, True, True, False, False, 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 0x000000004b7489f8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004b7489f8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004b7489f8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004b7418e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004f22d868>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004b748f70>, <W_TypeObject 'GenericAlias' at 0x4b525fa0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x450c5910>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x450c5910>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x450c5910>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x450c5910>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x468dcd20>>
w_obj = <W_TypeObject 'ellipsis' at 0x450c5910>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x450c5910>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x468dcd20>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x450c5910>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x468dcd20>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x468dcd20>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x468dcd20>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004c6adda8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x00000000483661d8>
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 0x00000000482a83a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000482a83a0>
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 0x000000004832fda8>
key = (((True, True, True, False, False, 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 0x000000004832fda8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004832fda8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004832fda8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000048c740a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000048ce2b10>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000004836c368>, <W_TypeObject 'GenericAlias' at 0x510014b0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x51053670>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x51053670>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x51053670>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x51053670>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3ac5bef0>>
w_obj = <W_TypeObject 'ellipsis' at 0x51053670>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x51053670>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3ac5bef0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x51053670>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3ac5bef0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3ac5bef0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3ac5bef0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000051e5e2f0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000052178b10>
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 0x0000000052190760>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000052190760>
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 0x0000000052193130>
key = (((True, True, True, False, False, 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 0x0000000052193130>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000052193130>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000052193130>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000005229e460>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000522cd590>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000521936a8>, <W_TypeObject 'GenericAlias' at 0x524ea2c0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x52563638>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x52563638>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x52563638>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x52563638>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x48935da0>>
w_obj = <W_TypeObject 'ellipsis' at 0x52563638>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x52563638>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x48935da0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x52563638>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x48935da0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x48935da0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x48935da0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000052d85790>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000053c46638>
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 0x0000000053c1efe0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000053c1efe0>
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 0x0000000053c48218>
key = (((True, True, True, False, False, 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 0x0000000053c48218>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000053c48218>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000053c48218>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000053c1fee0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000053df6f00>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000053c48790>, <W_TypeObject 'GenericAlias' at 0x5407e598>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x540d50f8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x540d50f8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x540d50f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x540d50f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4bca6e80>>
w_obj = <W_TypeObject 'ellipsis' at 0x540d50f8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x540d50f8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4bca6e80>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x540d50f8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4bca6e80>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4bca6e80>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4bca6e80>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000041b00098>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000041716c00>
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 0x000000004497d060>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004497d060>
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 0x00000000467dd590>
key = (((True, True, True, False, False, 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 0x00000000467dd590>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000467dd590>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000467dd590>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000449c12e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004797c6b0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000046804368>, <W_TypeObject 'GenericAlias' at 0x4d29c918>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4d65f328>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4d65f328>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4d65f328>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4d65f328>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4cc81f00>>
w_obj = <W_TypeObject 'ellipsis' at 0x4d65f328>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4d65f328>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4cc81f00>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4d65f328>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4cc81f00>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4cc81f00>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4cc81f00>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004163c7a0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000003fec2840>
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 0x00000000426fdf60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000426fdf60>
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 0x000000005401afa8>
key = (((True, True, True, False, False, 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 0x000000005401afa8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000005401afa8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000005401afa8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000041213420>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000053ffc1e0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000005401b520>, <W_TypeObject 'GenericAlias' at 0x496b3b08>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x496a1600>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x496a1600>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x496a1600>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x496a1600>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3bddaad0>>
w_obj = <W_TypeObject 'ellipsis' at 0x496a1600>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x496a1600>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3bddaad0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x496a1600>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3bddaad0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3bddaad0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3bddaad0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000042ebd088>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000043457ab0>
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 0x0000000041cdc220>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000041cdc220>
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 0x0000000041cc86e8>
key = (((True, True, True, False, False, 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 0x0000000041cc86e8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000041cc86e8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000041cc86e8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000041cdd660>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000419bf7f8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000041cc8c60>, <W_TypeObject 'GenericAlias' at 0x5107f2b8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x462952f0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x462952f0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x462952f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x462952f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2f14ab30>>
w_obj = <W_TypeObject 'ellipsis' at 0x462952f0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x462952f0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2f14ab30>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x462952f0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2f14ab30>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2f14ab30>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2f14ab30>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000045a5bb50>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000045f32e80>
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 0x0000000048869b60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000048869b60>
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 0x0000000048881590>
key = (((True, True, True, False, False, 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 0x0000000048881590>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000048881590>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000048881590>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000445430e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004be34250>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000048881b08>, <W_TypeObject 'GenericAlias' at 0x50333788>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4690f088>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4690f088>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4690f088>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4690f088>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4ae11030>>
w_obj = <W_TypeObject 'ellipsis' at 0x4690f088>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4690f088>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4ae11030>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4690f088>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4ae11030>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4ae11030>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4ae11030>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000049c9f808>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004b93d4c0>
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 0x0000000050e336a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000050e336a0>
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 0x0000000050e5c3d8>
key = (((True, True, True, False, False, 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 0x0000000050e5c3d8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000050e5c3d8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000050e5c3d8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004b104a60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000048db7ec0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000050e5c950>, <W_TypeObject 'GenericAlias' at 0x4b9a20c8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b9cbe88>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b9cbe88>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b9cbe88>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b9cbe88>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45938340>>
w_obj = <W_TypeObject 'ellipsis' at 0x4b9cbe88>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4b9cbe88>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45938340>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4b9cbe88>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45938340>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45938340>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45938340>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004d94c458>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004f985240>
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 0x0000000047d9c4a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000047d9c4a0>
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 0x0000000047d95718>
key = (((True, True, True, False, False, 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 0x0000000047d95718>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000047d95718>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000047d95718>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000047d9dfa0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000051fe1210>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000047d95c90>, <W_TypeObject 'GenericAlias' at 0x4fb40918>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4add7f68>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4add7f68>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4add7f68>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4add7f68>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4dc15570>>
w_obj = <W_TypeObject 'ellipsis' at 0x4add7f68>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4add7f68>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4dc15570>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4add7f68>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4dc15570>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4dc15570>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4dc15570>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004f9455b0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000048d08930>
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 0x000000005350e660>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000005350e660>
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 0x00000000535199f0>
key = (((True, True, True, False, False, 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 0x00000000535199f0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000535199f0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000535199f0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000053665860>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004494e6b0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000053519f68>, <W_TypeObject 'GenericAlias' at 0x4d75f7c0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4d7260c8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4d7260c8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4d7260c8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4d7260c8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x42c4e4d0>>
w_obj = <W_TypeObject 'ellipsis' at 0x4d7260c8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4d7260c8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x42c4e4d0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4d7260c8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x42c4e4d0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x42c4e4d0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x42c4e4d0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004c574b60>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000005096ac78>
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 0x000000005090bee0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000005090bee0>
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 0x00000000508f9de0>
key = (((True, True, True, False, False, 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 0x00000000508f9de0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000508f9de0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000508f9de0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000053bd70e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004648e838>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000053bd8598>, <W_TypeObject 'GenericAlias' at 0x52653280>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x53265328>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x53265328>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x53265328>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x53265328>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d2ef340>>
w_obj = <W_TypeObject 'ellipsis' at 0x53265328>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x53265328>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d2ef340>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x53265328>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d2ef340>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d2ef340>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d2ef340>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000051220548>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004a947d58>
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 0x00000000528462e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000528462e0>
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 0x000000005282cf70>
key = (((True, True, True, False, False, 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 0x000000005282cf70>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000005282cf70>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000005282cf70>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000528473e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000052e36678>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000005282d4e8>, <W_TypeObject 'GenericAlias' at 0x49513018>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4aa49c20>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4aa49c20>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4aa49c20>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4aa49c20>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43b58300>>
w_obj = <W_TypeObject 'ellipsis' at 0x4aa49c20>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4aa49c20>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43b58300>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4aa49c20>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43b58300>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43b58300>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43b58300>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000053dda368>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x00000000501cb498>
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 0x000000004f4a0f20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004f4a0f20>
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 0x000000004f4ac988>
key = (((True, True, True, False, False, 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 0x000000004f4ac988>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004f4ac988>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004f4ac988>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000509dc1a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000050a39be8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004f4acf00>, <W_TypeObject 'GenericAlias' at 0x393cb2f0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x32cf0448>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x32cf0448>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x32cf0448>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x32cf0448>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49c63530>>
w_obj = <W_TypeObject 'ellipsis' at 0x32cf0448>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x32cf0448>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49c63530>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x32cf0448>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49c63530>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49c63530>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49c63530>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000003fb9b808>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000003df575d8>
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 0x000000004796f120>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004796f120>
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 0x000000004b939a98>
key = (((True, True, True, False, False, 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 0x000000004b939a98>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004b939a98>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004b939a98>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000479c6de0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004c1be950>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000004b996058>, <W_TypeObject 'GenericAlias' at 0x4782ae90>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x49fa4480>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x49fa4480>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x49fa4480>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x49fa4480>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2e48e8c0>>
w_obj = <W_TypeObject 'ellipsis' at 0x49fa4480>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x49fa4480>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2e48e8c0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x49fa4480>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2e48e8c0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2e48e8c0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2e48e8c0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000041fa47a0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000042597ec0>
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 0x0000000047206620>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000047206620>
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 0x000000004728f8d8>
key = (((True, True, True, False, False, 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 0x000000004728f8d8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004728f8d8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004728f8d8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000047207ae0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000053751248>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004728fe50>, <W_TypeObject 'GenericAlias' at 0x423526b0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x42342db0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x42342db0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x42342db0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x42342db0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x430a5200>>
w_obj = <W_TypeObject 'ellipsis' at 0x42342db0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x42342db0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x430a5200>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x42342db0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x430a5200>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x430a5200>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x430a5200>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x00000000434ab5b0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000043f21a38>
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 0x000000004e5082e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004e5082e0>
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 0x0000000046bd7a28>
key = (((True, True, True, False, False, 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 0x0000000046bd7a28>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000046bd7a28>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000046bd7a28>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004e5098e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000047986480>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000046bd7fa0>, <W_TypeObject 'GenericAlias' at 0x4d826368>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b1017f8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b1017f8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b1017f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b1017f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4dc15b00>>
w_obj = <W_TypeObject 'ellipsis' at 0x4b1017f8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4b1017f8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4dc15b00>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4b1017f8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4dc15b00>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4dc15b00>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4dc15b00>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x00000000478a7da8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000047b2e728>
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 0x000000004b680920>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004b680920>
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 0x000000004b66bef8>
key = (((True, True, True, False, False, 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 0x000000004b66bef8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004b66bef8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004b66bef8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004b681b20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000051d8e410>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000004a6e24b8>, <W_TypeObject 'GenericAlias' at 0x420df0f8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4f331360>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4f331360>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4f331360>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4f331360>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49f10ca0>>
w_obj = <W_TypeObject 'ellipsis' at 0x4f331360>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4f331360>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49f10ca0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4f331360>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49f10ca0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49f10ca0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49f10ca0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004af65cb8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004bf54098>
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 0x0000000054188de0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000054188de0>
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 0x000000005416af70>
key = (((True, True, True, False, False, 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 0x000000005416af70>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000005416af70>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000005416af70>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000005241c1a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000052414640>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000005416b4e8>, <W_TypeObject 'GenericAlias' at 0x45daa598>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x45ded280>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x45ded280>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x45ded280>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x45ded280>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x42ac94a0>>
w_obj = <W_TypeObject 'ellipsis' at 0x45ded280>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x45ded280>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x42ac94a0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x45ded280>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x42ac94a0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x42ac94a0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x42ac94a0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004dec9cb8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004fcd81d8>
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 0x000000005113a2e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000005113a2e0>
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 0x000000005112f670>
key = (((True, True, True, False, False, 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 0x000000005112f670>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000005112f670>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000005112f670>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000005113bea0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000536d6800>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000005112fbe8>, <W_TypeObject 'GenericAlias' at 0x4cfbdd00>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x50638fa8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x50638fa8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x50638fa8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x50638fa8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x457ea250>>
w_obj = <W_TypeObject 'ellipsis' at 0x50638fa8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x50638fa8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x457ea250>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x50638fa8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x457ea250>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x457ea250>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x457ea250>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004ce28b60>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000048e23ba0>
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 0x000000004679aaa0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004679aaa0>
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 0x000000004679efa8>
key = (((True, True, True, False, False, 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 0x000000004679efa8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004679efa8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004679efa8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004679be20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000052864d78>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004679f520>, <W_TypeObject 'GenericAlias' at 0x493df0c0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48af3cc8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48af3cc8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48af3cc8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48af3cc8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4be9b680>>
w_obj = <W_TypeObject 'ellipsis' at 0x48af3cc8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x48af3cc8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4be9b680>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x48af3cc8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4be9b680>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4be9b680>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4be9b680>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x00000000522e2cc8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004e9cc2a0>
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 0x000000004c39bae0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004c39bae0>
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 0x00000000534d6090>
key = (((True, True, True, False, False, 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 0x00000000534d6090>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000534d6090>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000534d6090>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000534c1660>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000051c79d38>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000534d6608>, <W_TypeObject 'GenericAlias' at 0x50159168>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5015d8d8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5015d8d8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5015d8d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5015d8d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4ea31d20>>
w_obj = <W_TypeObject 'ellipsis' at 0x5015d8d8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x5015d8d8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4ea31d20>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x5015d8d8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4ea31d20>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4ea31d20>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4ea31d20>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004a974908>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004483cde0>
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 0x000000004d178a20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004d178a20>
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 0x000000004d1a1948>
key = (((True, True, True, False, False, 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 0x000000004d1a1948>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004d1a1948>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004d1a1948>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004d179ca0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000054427360>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004d1a1ec0>, <W_TypeObject 'GenericAlias' at 0x4c878e20>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4c8b1bb0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4c8b1bb0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4c8b1bb0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4c8b1bb0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d7f9ee0>>
w_obj = <W_TypeObject 'ellipsis' at 0x4c8b1bb0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4c8b1bb0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d7f9ee0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4c8b1bb0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d7f9ee0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d7f9ee0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d7f9ee0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000046fd76a0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000041e44688>
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 0x000000003bbdc160>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000003bbdc160>
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 0x000000004283f6e0>
key = (((True, True, True, False, False, 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 0x000000004283f6e0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004283f6e0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004283f6e0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000003c630e20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000042df9718>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004283fde0>, <W_TypeObject 'GenericAlias' at 0x457499f0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x45971f30>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x45971f30>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x45971f30>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x45971f30>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4763e1d0>>
w_obj = <W_TypeObject 'ellipsis' at 0x45971f30>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x45971f30>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4763e1d0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x45971f30>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4763e1d0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4763e1d0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4763e1d0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000053fb0098>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x00000000404a66b0>
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 0x000000004cb13b60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004cb13b60>
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 0x000000004ea9fec0>
key = (((True, True, True, False, False, 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 0x000000004ea9fec0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004ea9fec0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004ea9fec0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004cb7d2a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004aae5328>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004eab2480>, <W_TypeObject 'GenericAlias' at 0x51052b80>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x518ba6b0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x518ba6b0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x518ba6b0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x518ba6b0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47c3e730>>
w_obj = <W_TypeObject 'ellipsis' at 0x518ba6b0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x518ba6b0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47c3e730>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x518ba6b0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47c3e730>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47c3e730>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47c3e730>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000041fa4200>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000042deaf70>
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 0x000000004b142fe0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004b142fe0>
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 0x000000004aa3ee90>
key = (((True, True, True, False, False, 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 0x000000004aa3ee90>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004aa3ee90>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004aa3ee90>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000049205620>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000052149a28>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000004aa3f408>, <W_TypeObject 'GenericAlias' at 0x53215050>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4f974870>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4f974870>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4f974870>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4f974870>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3a3a4db0>>
w_obj = <W_TypeObject 'ellipsis' at 0x4f974870>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4f974870>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3a3a4db0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4f974870>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3a3a4db0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3a3a4db0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3a3a4db0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000044c56098>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000045bdc548>
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 0x000000005379c360>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000005379c360>
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 0x00000000419f2218>
key = (((True, True, True, False, False, 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 0x00000000419f2218>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000419f2218>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000419f2218>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000005379d520>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000051795be8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000419f2790>, <W_TypeObject 'GenericAlias' at 0x4271e678>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x42d49130>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x42d49130>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x42d49130>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x42d49130>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3daad930>>
w_obj = <W_TypeObject 'ellipsis' at 0x42d49130>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x42d49130>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3daad930>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x42d49130>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3daad930>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3daad930>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3daad930>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000049c9e980>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000049c90840>
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 0x0000000046d35e20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000046d35e20>
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 0x0000000046cf1f30>
key = (((True, True, True, False, False, 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 0x0000000046cf1f30>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000046cf1f30>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000046cf1f30>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000051fe50a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000049247210>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000051fd04f0>, <W_TypeObject 'GenericAlias' at 0x4a739408>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a708918>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a708918>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a708918>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a708918>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3e1d64c0>>
w_obj = <W_TypeObject 'ellipsis' at 0x4a708918>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4a708918>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3e1d64c0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4a708918>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3e1d64c0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3e1d64c0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3e1d64c0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004d94d100>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004de9d088>
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 0x00000000508035a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000508035a0>
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 0x00000000507e6790>
key = (((True, True, True, False, False, 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 0x00000000507e6790>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000507e6790>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000507e6790>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000048b2f160>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004662cf70>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000507e6d08>, <W_TypeObject 'GenericAlias' at 0x4fcf0100>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4fd29868>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4fd29868>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4fd29868>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4fd29868>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4ea248a0>>
w_obj = <W_TypeObject 'ellipsis' at 0x4fd29868>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4fd29868>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4ea248a0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4fd29868>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4ea248a0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4ea248a0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4ea248a0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004ce29088>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004c821fd8>
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 0x0000000045179be0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000045179be0>
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 0x000000004518d8a0>
key = (((True, True, True, False, False, 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 0x000000004518d8a0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004518d8a0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004518d8a0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000491d33a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000453eede8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000052fac100>, <W_TypeObject 'GenericAlias' at 0x5048cc28>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x51f8a8e0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x51f8a8e0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x51f8a8e0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x51f8a8e0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49a703b0>>
w_obj = <W_TypeObject 'ellipsis' at 0x51f8a8e0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x51f8a8e0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49a703b0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x51f8a8e0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49a703b0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49a703b0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49a703b0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000052307c40>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000005400d4e8>
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 0x000000004c436860>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004c436860>
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 0x000000004c4abd38>
key = (((True, True, True, False, False, 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 0x000000004c4abd38>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004c4abd38>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004c4abd38>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004c437fa0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004995d6a8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000004c4a02f8>, <W_TypeObject 'GenericAlias' at 0x473cd788>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4fdc0560>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4fdc0560>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4fdc0560>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4fdc0560>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49d35050>>
w_obj = <W_TypeObject 'ellipsis' at 0x4fdc0560>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4fdc0560>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49d35050>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4fdc0560>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49d35050>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49d35050>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49d35050>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x00000000530fc980>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004c8544f8>
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 0x000000004c646620>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004c646620>
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 0x000000004c63ba60>
key = (((True, True, True, False, False, 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 0x000000004c63ba60>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004c63ba60>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004c63ba60>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004c647820>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000048513c20>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000050962020>, <W_TypeObject 'GenericAlias' at 0x4b1bdda8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44878ad8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44878ad8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44878ad8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44878ad8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x490a98f0>>
w_obj = <W_TypeObject 'ellipsis' at 0x44878ad8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x44878ad8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x490a98f0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x44878ad8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x490a98f0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x490a98f0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x490a98f0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004dd0fad8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000005195c5e8>
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 0x000000005197aee0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000005197aee0>
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 0x00000000465b1478>
key = (((True, True, True, False, False, 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 0x00000000465b1478>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000465b1478>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000465b1478>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000005197be60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000529d7248>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000465b19f0>, <W_TypeObject 'GenericAlias' at 0x41e4c678>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x485d5ef8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x485d5ef8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x485d5ef8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x485d5ef8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4c07adc0>>
w_obj = <W_TypeObject 'ellipsis' at 0x485d5ef8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x485d5ef8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4c07adc0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x485d5ef8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4c07adc0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4c07adc0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4c07adc0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x00000000539eb6a0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x00000000550b6e58>
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 0x0000000055394060>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000055394060>
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 0x0000000055387a28>
key = (((True, True, True, False, False, 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 0x0000000055387a28>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000055387a28>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000055387a28>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000055395660>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000555c8288>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000055387fa0>, <W_TypeObject 'GenericAlias' at 0x4e87b0c0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x544b45d0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x544b45d0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x544b45d0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x544b45d0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49d355e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x544b45d0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x544b45d0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49d355e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x544b45d0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49d355e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49d355e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49d355e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000046fd73d0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000040529150>
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 0x00000000456b4c60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000456b4c60>
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 0x0000000047a96560>
key = (((True, True, True, False, False, 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 0x0000000047a96560>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000047a96560>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000047a96560>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004584f0a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000049098790>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000047a96ad8>, <W_TypeObject 'GenericAlias' at 0x4dbd7718>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4de48678>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4de48678>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4de48678>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4de48678>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3578abf0>>
w_obj = <W_TypeObject 'ellipsis' at 0x4de48678>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4de48678>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3578abf0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4de48678>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3578abf0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3578abf0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3578abf0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000053fb1100>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000003fa81f60>
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 0x00000000459a17e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000459a17e0>
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 0x0000000050f3d398>
key = (((True, True, True, False, False, 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 0x0000000050f3d398>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000050f3d398>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000050f3d398>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000424ef820>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000522e5670>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000050f3da60>, <W_TypeObject 'GenericAlias' at 0x4e907a28>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x479eead8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x479eead8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x479eead8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x479eead8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x354b8560>>
w_obj = <W_TypeObject 'ellipsis' at 0x479eead8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x479eead8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x354b8560>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x479eead8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x354b8560>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x354b8560>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x354b8560>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000042345790>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000043b87b50>
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 0x0000000047ad9860>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000047ad9860>
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 0x000000004a739d00>
key = (((True, True, True, False, False, 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 0x000000004a739d00>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004a739d00>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004a739d00>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000425deca0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004fd55980>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004a7482c0>, <W_TypeObject 'GenericAlias' at 0x4d674790>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x41e7b0f8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x41e7b0f8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x41e7b0f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x41e7b0f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x44e17220>>
w_obj = <W_TypeObject 'ellipsis' at 0x41e7b0f8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x41e7b0f8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x44e17220>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x41e7b0f8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x44e17220>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x44e17220>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x44e17220>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x00000000458d78f8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000046dd2e58>
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 0x0000000040dea5e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000040dea5e0>
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 0x000000004ae73248>
key = (((True, True, True, False, False, 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 0x000000004ae73248>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004ae73248>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004ae73248>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000040deb9e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000525a6f38>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004ae737c0>, <W_TypeObject 'GenericAlias' at 0x4840d718>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b0234e8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b0234e8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b0234e8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b0234e8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43aae5c0>>
w_obj = <W_TypeObject 'ellipsis' at 0x4b0234e8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4b0234e8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43aae5c0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4b0234e8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43aae5c0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43aae5c0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43aae5c0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004bbb6278>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004bb16138>
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 0x000000005438be60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000005438be60>
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 0x00000000512152b8>
key = (((True, True, True, False, False, 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 0x00000000512152b8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000512152b8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000512152b8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000050aa12a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004b1d72b8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000051215830>, <W_TypeObject 'GenericAlias' at 0x4a643d38>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a630410>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a630410>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a630410>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a630410>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d4ba5a0>>
w_obj = <W_TypeObject 'ellipsis' at 0x4a630410>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4a630410>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d4ba5a0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4a630410>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d4ba5a0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d4ba5a0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d4ba5a0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004fa1bcb8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004f7d1740>
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 0x00000000421e1960>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000421e1960>
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 0x000000004e896448>
key = (((True, True, True, False, False, 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 0x000000004e896448>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004e896448>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004e896448>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004d556ee0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000005376f670>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004e8969c0>, <W_TypeObject 'GenericAlias' at 0x46c7bb08>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x46c8b088>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x46c8b088>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x46c8b088>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x46c8b088>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4f9ae130>>
w_obj = <W_TypeObject 'ellipsis' at 0x46c8b088>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x46c8b088>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4f9ae130>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x46c8b088>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4f9ae130>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4f9ae130>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4f9ae130>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000048cc8110>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000045146c00>
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 0x000000004d6d7520>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004d6d7520>
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 0x000000005183c020>
key = (((True, True, True, False, False, 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 0x000000005183c020>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000005183c020>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000005183c020>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000044b72720>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004e52a4b8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000005183c598>, <W_TypeObject 'GenericAlias' at 0x49060950>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4f132800>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4f132800>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4f132800>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4f132800>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3e465b50>>
w_obj = <W_TypeObject 'ellipsis' at 0x4f132800>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4f132800>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3e465b50>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4f132800>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3e465b50>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3e465b50>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3e465b50>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x00000000542b1970>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000047143c40>
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 0x00000000507233a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000507233a0>
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 0x0000000050733830>
key = (((True, True, True, False, False, 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 0x0000000050733830>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000050733830>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000050733830>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004f2d2ae0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004c365328>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000050733da8>, <W_TypeObject 'GenericAlias' at 0x5233a6b0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x523301a8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x523301a8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x523301a8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x523301a8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4e190e90>>
w_obj = <W_TypeObject 'ellipsis' at 0x523301a8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x523301a8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4e190e90>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x523301a8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4e190e90>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4e190e90>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4e190e90>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x00000000484f6b60>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000005373f7b8>
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 0x00000000518dfb60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000518dfb60>
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 0x00000000518c0de8>
key = (((True, True, True, False, False, 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 0x00000000518c0de8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000518c0de8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000518c0de8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004ef0aea0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004b5f5408>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000518c1360>, <W_TypeObject 'GenericAlias' at 0x4a9714e8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a927ef8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a927ef8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a927ef8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a927ef8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43ac5b70>>
w_obj = <W_TypeObject 'ellipsis' at 0x4a927ef8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4a927ef8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43ac5b70>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4a927ef8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43ac5b70>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43ac5b70>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43ac5b70>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000005561eb60>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000047e02bd8>
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 0x0000000047e19de0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000047e19de0>
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 0x0000000047e20608>
key = (((True, True, True, False, False, 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 0x0000000047e20608>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000047e20608>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000047e20608>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000528fd1e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004ef4fad0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000047e20b80>, <W_TypeObject 'GenericAlias' at 0x51b88cd0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x52f6ff68>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x52f6ff68>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x52f6ff68>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x52f6ff68>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x449027f0>>
w_obj = <W_TypeObject 'ellipsis' at 0x52f6ff68>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x52f6ff68>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x449027f0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x52f6ff68>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x449027f0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x449027f0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x449027f0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004ac13970>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000003bf6f0d8>
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 0x000000003b7d97e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000003b7d97e0>
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 0x0000000052c48e20>
key = (((True, True, True, False, False, 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 0x0000000052c48e20>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000052c48e20>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000052c48e20>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000038a21060>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004294c4f0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000052c49398>, <W_TypeObject 'GenericAlias' at 0x44795b08>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44b08950>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44b08950>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44b08950>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44b08950>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45b54500>>
w_obj = <W_TypeObject 'ellipsis' at 0x44b08950>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x44b08950>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45b54500>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x44b08950>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45b54500>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45b54500>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45b54500>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000053e09ad8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x00000000400710b0>
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 0x000000004c2c10a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004c2c10a0>
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 0x00000000489ea0c8>
key = (((True, True, True, False, False, 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 0x00000000489ea0c8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000489ea0c8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000489ea0c8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004d2a73a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000460211d8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000489ea640>, <W_TypeObject 'GenericAlias' at 0x4841b670>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48d8a9f8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48d8a9f8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48d8a9f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48d8a9f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3a8f0af0>>
w_obj = <W_TypeObject 'ellipsis' at 0x48d8a9f8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x48d8a9f8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3a8f0af0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x48d8a9f8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3a8f0af0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3a8f0af0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3a8f0af0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x00000000423d1268>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000042afea48>
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 0x00000000496d9ee0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000496d9ee0>
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 0x0000000049531408>
key = (((True, True, True, False, False, 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 0x0000000049531408>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000049531408>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000049531408>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000451c1060>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000423a2918>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000049531980>, <W_TypeObject 'GenericAlias' at 0x51871b40>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a52b600>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a52b600>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a52b600>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a52b600>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4eeb1550>>
w_obj = <W_TypeObject 'ellipsis' at 0x4a52b600>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4a52b600>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4eeb1550>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4a52b600>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4eeb1550>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4eeb1550>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4eeb1550>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x00000000478a6f98>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000045602160>
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 0x000000004d0c5aa0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004d0c5aa0>
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 0x0000000046c38e58>
key = (((True, True, True, False, False, 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 0x0000000046c38e58>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000046c38e58>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000046c38e58>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004e2d1420>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000048a9a250>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000046c393d0>, <W_TypeObject 'GenericAlias' at 0x53e22c28>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4799c4f0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4799c4f0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4799c4f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4799c4f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4556c780>>
w_obj = <W_TypeObject 'ellipsis' at 0x4799c4f0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4799c4f0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4556c780>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4799c4f0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4556c780>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4556c780>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4556c780>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004d2b2728>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004865c8b8>
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 0x000000004f625620>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004f625620>
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 0x00000000449ff520>
key = (((True, True, True, False, False, 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 0x00000000449ff520>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000449ff520>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000449ff520>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004530fc60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000455fb2f0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000449ffa98>, <W_TypeObject 'GenericAlias' at 0x523e0c28>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x51c7c448>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x51c7c448>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x51c7c448>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x51c7c448>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x42936250>>
w_obj = <W_TypeObject 'ellipsis' at 0x51c7c448>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x51c7c448>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x42936250>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x51c7c448>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x42936250>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x42936250>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x42936250>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004c574e30>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004cd34778>
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 0x0000000050bb4c20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000050bb4c20>
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 0x0000000048fca988>
key = (((True, True, True, False, False, 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 0x0000000048fca988>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000048fca988>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000048fca988>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000050bb5ee0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000045cb6138>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000048fcaf00>, <W_TypeObject 'GenericAlias' at 0x4b3fe1e0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b50d830>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b50d830>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b50d830>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b50d830>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4e421db0>>
w_obj = <W_TypeObject 'ellipsis' at 0x4b50d830>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4b50d830>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4e421db0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4b50d830>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4e421db0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4e421db0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4e421db0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000053d743e0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000048463380>
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 0x000000004609c520>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004609c520>
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 0x000000004d7040c8>
key = (((True, True, True, False, False, 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 0x000000004d7040c8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004d7040c8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004d7040c8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004609d720>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004433aec8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004d704640>, <W_TypeObject 'GenericAlias' at 0x44817d38>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44805718>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44805718>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44805718>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44805718>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x459374d0>>
w_obj = <W_TypeObject 'ellipsis' at 0x44805718>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x44805718>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x459374d0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x44805718>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x459374d0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x459374d0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x459374d0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004f03fcb8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000052179ad8>
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 0x000000004f0a0be0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004f0a0be0>
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 0x000000004f07ba98>
key = (((True, True, True, False, False, 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 0x000000004f07ba98>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004f07ba98>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004f07ba98>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004f0a1d20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000051d1bc58>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000045474058>, <W_TypeObject 'GenericAlias' at 0x48de2288>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x40de9bb0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x40de9bb0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x40de9bb0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x40de9bb0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3944d2f0>>
w_obj = <W_TypeObject 'ellipsis' at 0x40de9bb0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x40de9bb0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3944d2f0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x40de9bb0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3944d2f0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3944d2f0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3944d2f0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x00000000529c2980>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000049518ac0>
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 0x000000004ec29320>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004ec29320>
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 0x000000004ebd7b78>
key = (((True, True, True, False, False, 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 0x000000004ebd7b78>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004ebd7b78>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004ebd7b78>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000050f7a4e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004d6244b8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000004bd56138>, <W_TypeObject 'GenericAlias' at 0x486efe50>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4870a058>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4870a058>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4870a058>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4870a058>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3a1d53b0>>
w_obj = <W_TypeObject 'ellipsis' at 0x4870a058>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4870a058>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3a1d53b0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4870a058>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3a1d53b0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3a1d53b0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3a1d53b0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x00000000442ca2f0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000051c10278>
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 0x000000004e29fc60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004e29fc60>
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 0x000000004e2e5168>
key = (((True, True, True, False, False, 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 0x000000004e2e5168>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004e2e5168>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004e2e5168>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000052a78de0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004b552fa8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004e2e56e0>, <W_TypeObject 'GenericAlias' at 0x47ddd9b8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47e491d8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47e491d8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47e491d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47e491d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x554a4ac0>>
w_obj = <W_TypeObject 'ellipsis' at 0x47e491d8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x47e491d8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x554a4ac0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x47e491d8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x554a4ac0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x554a4ac0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x554a4ac0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000041d50db8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004633c188>
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 0x000000004946e060>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004946e060>
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 0x000000004946a3d8>
key = (((True, True, True, False, False, 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 0x000000004946a3d8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004946a3d8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004946a3d8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004946f9a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000053abb948>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000004946be18>, <W_TypeObject 'GenericAlias' at 0x5473cfe0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5476fde0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5476fde0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5476fde0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5476fde0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x35af2480>>
w_obj = <W_TypeObject 'ellipsis' at 0x5476fde0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x5476fde0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x35af2480>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x5476fde0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x35af2480>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x35af2480>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x35af2480>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000056048458>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x00000000563ceed0>
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 0x000000005609e7e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000005609e7e0>
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 0x0000000055e1a058>
key = (((True, True, True, False, False, 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 0x0000000055e1a058>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000055e1a058>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000055e1a058>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000054b8a4e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000055527ad0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000055e1a5d0>, <W_TypeObject 'GenericAlias' at 0x4225fe50>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x422e19f0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x422e19f0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x422e19f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x422e19f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x35acf180>>
w_obj = <W_TypeObject 'ellipsis' at 0x422e19f0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x422e19f0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x35acf180>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x422e19f0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x35acf180>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x35acf180>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x35acf180>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000005452f3d0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x00000000407b0f70>
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 0x000000004762b7e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004762b7e0>
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 0x000000004d9a2de8>
key = (((True, True, True, False, False, 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 0x000000004d9a2de8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004d9a2de8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004d9a2de8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000477130e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004e3c5600>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000004d9f8918>, <W_TypeObject 'GenericAlias' at 0x4e5f0b80>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b021210>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b021210>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b021210>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b021210>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45c74320>>
w_obj = <W_TypeObject 'ellipsis' at 0x4b021210>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4b021210>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45c74320>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4b021210>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45c74320>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45c74320>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45c74320>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000037ee6db8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x00000000423c1448>
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 0x000000005059c460>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000005059c460>
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 0x0000000045001be8>
key = (((True, True, True, False, False, 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 0x0000000045001be8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000045001be8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000045001be8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000005059dae0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004d0ce4f0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000521ba6b0>, <W_TypeObject 'GenericAlias' at 0x4795d8a0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4d83d0f8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4d83d0f8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4d83d0f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4d83d0f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x477c88b0>>
w_obj = <W_TypeObject 'ellipsis' at 0x4d83d0f8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4d83d0f8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x477c88b0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4d83d0f8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x477c88b0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x477c88b0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x477c88b0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x00000000458ac200>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000043f552b8>
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 0x000000004fb734a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004fb734a0>
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 0x0000000053d51be8>
key = (((True, True, True, False, False, 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 0x0000000053d51be8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000053d51be8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000053d51be8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004fb5b120>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000046c89088>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000053d342f8>, <W_TypeObject 'GenericAlias' at 0x43243fa0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5227a678>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5227a678>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5227a678>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5227a678>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x477c4fd0>>
w_obj = <W_TypeObject 'ellipsis' at 0x5227a678>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x5227a678>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x477c4fd0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x5227a678>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x477c4fd0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x477c4fd0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x477c4fd0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004d2b2bd8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x00000000478ff920>
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 0x000000004e99d420>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004e99d420>
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 0x000000004a7b6870>
key = (((True, True, True, False, False, 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 0x000000004a7b6870>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004a7b6870>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004a7b6870>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000005009aea0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004774cd40>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000004a7b6de8>, <W_TypeObject 'GenericAlias' at 0x51b64448>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x51b5ae58>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x51b5ae58>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x51b5ae58>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x51b5ae58>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47af0a00>>
w_obj = <W_TypeObject 'ellipsis' at 0x51b5ae58>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x51b5ae58>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47af0a00>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x51b5ae58>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47af0a00>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47af0a00>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47af0a00>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004f220188>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004ba17628>
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 0x000000004a4557a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004a4557a0>
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 0x0000000051206db0>
key = (((True, True, True, False, False, 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 0x0000000051206db0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000051206db0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000051206db0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004a428da0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004da33868>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000051207328>, <W_TypeObject 'GenericAlias' at 0x51db1130>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47178988>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47178988>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47178988>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47178988>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x44532cc0>>
w_obj = <W_TypeObject 'ellipsis' at 0x47178988>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x47178988>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x44532cc0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x47178988>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x44532cc0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x44532cc0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x44532cc0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000053e1d268>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004f809998>
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 0x00000000502c38e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000502c38e0>
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 0x000000005057f788>
key = (((True, True, True, False, False, 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 0x000000005057f788>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000005057f788>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000005057f788>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000049712d20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000046cf1da8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000005057fd00>, <W_TypeObject 'GenericAlias' at 0x4b43d868>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48ba1868>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48ba1868>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48ba1868>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48ba1868>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47c2ff50>>
w_obj = <W_TypeObject 'ellipsis' at 0x48ba1868>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x48ba1868>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47c2ff50>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x48ba1868>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47c2ff50>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47c2ff50>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47c2ff50>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x00000000484d1ad8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x00000000491fecc8>
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 0x0000000041d8cb20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000041d8cb20>
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 0x0000000041da92b8>
key = (((True, True, True, False, False, 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 0x0000000041da92b8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000041da92b8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000041da92b8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000041d8dce0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004dfbf7f8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000041da9830>, <W_TypeObject 'GenericAlias' at 0x4e0c3b78>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5434e640>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5434e640>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5434e640>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5434e640>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x469e3470>>
w_obj = <W_TypeObject 'ellipsis' at 0x5434e640>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x5434e640>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x469e3470>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x5434e640>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x469e3470>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x469e3470>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x469e3470>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004ef3e980>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004a40e340>
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 0x0000000052ede8a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000052ede8a0>
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 0x0000000046e46020>
key = (((True, True, True, False, False, 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 0x0000000046e46020>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000046e46020>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000046e46020>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000052edfde0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000005298d9b8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000046e46598>, <W_TypeObject 'GenericAlias' at 0x48c7ba28>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48cb0bb8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48cb0bb8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48cb0bb8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48cb0bb8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43ac41c0>>
w_obj = <W_TypeObject 'ellipsis' at 0x48cb0bb8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x48cb0bb8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43ac41c0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x48cb0bb8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43ac41c0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43ac41c0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43ac41c0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004b556f98>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x00000000549d03e0>
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 0x000000004a2348e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004a2348e0>
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 0x000000004a1e3cc8>
key = (((True, True, True, False, False, 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 0x000000004a1e3cc8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004a1e3cc8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004a1e3cc8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004a235aa0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004e798448>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000054b38288>, <W_TypeObject 'GenericAlias' at 0x45390b10>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4536b9b8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4536b9b8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4536b9b8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4536b9b8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4276ce60>>
w_obj = <W_TypeObject 'ellipsis' at 0x4536b9b8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4536b9b8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4276ce60>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4536b9b8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4276ce60>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4276ce60>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4276ce60>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000050d03f88>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000054614a20>
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 0x00000000474c9160>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000474c9160>
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 0x00000000474f6b48>
key = (((True, True, True, False, False, 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 0x00000000474f6b48>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000474f6b48>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000474f6b48>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004af283a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004820b910>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000474f70c0>, <W_TypeObject 'GenericAlias' at 0x52084138>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5202cfa8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5202cfa8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5202cfa8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5202cfa8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x431fd490>>
w_obj = <W_TypeObject 'ellipsis' at 0x5202cfa8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x5202cfa8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x431fd490>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x5202cfa8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x431fd490>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x431fd490>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x431fd490>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004ef902f0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000054165178>
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 0x000000004252c120>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004252c120>
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 0x0000000043468918>
key = (((True, True, True, False, False, 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 0x0000000043468918>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000043468918>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000043468918>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004252d5e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000043fb87c8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000043468e90>, <W_TypeObject 'GenericAlias' at 0x47c560c8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47fa5670>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47fa5670>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47fa5670>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47fa5670>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3450efb0>>
w_obj = <W_TypeObject 'ellipsis' at 0x47fa5670>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x47fa5670>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3450efb0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x47fa5670>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3450efb0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3450efb0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3450efb0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000050a24818>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000003d0047f0>
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 0x000000004ede3a60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004ede3a60>
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 0x000000004ce04448>
key = (((True, True, True, False, False, 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 0x000000004ce04448>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004ce04448>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004ce04448>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004ee7d3a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004c82efe0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004ce049c0>, <W_TypeObject 'GenericAlias' at 0x53f2f520>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5403ed78>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5403ed78>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5403ed78>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5403ed78>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x42d70ba0>>
w_obj = <W_TypeObject 'ellipsis' at 0x5403ed78>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x5403ed78>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x42d70ba0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x5403ed78>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x42d70ba0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x42d70ba0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x42d70ba0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x00000000423d0a70>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000042ab2cf0>
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 0x0000000053de4fe0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000053de4fe0>
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 0x000000005152d8a0>
key = (((True, True, True, False, False, 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 0x000000005152d8a0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000005152d8a0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000005152d8a0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000053ea69a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000433ed7f8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000005152de18>, <W_TypeObject 'GenericAlias' at 0x53bb1750>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x529a85d0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x529a85d0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x529a85d0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x529a85d0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3c075c80>>
w_obj = <W_TypeObject 'ellipsis' at 0x529a85d0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x529a85d0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3c075c80>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x529a85d0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3c075c80>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3c075c80>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3c075c80>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000048f35880>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x00000000457f01b0>
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 0x000000005364e6a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000005364e6a0>
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 0x00000000454b0f38>
key = (((True, True, True, False, False, 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 0x00000000454b0f38>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000454b0f38>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000454b0f38>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000005364f9e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000053971a60>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000454b14b0>, <W_TypeObject 'GenericAlias' at 0x4c182480>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x53a70988>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x53a70988>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x53a70988>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x53a70988>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49d0fc20>>
w_obj = <W_TypeObject 'ellipsis' at 0x53a70988>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x53a70988>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49d0fc20>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x53a70988>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49d0fc20>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49d0fc20>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x49d0fc20>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004fa1aea8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x00000000499369d0>
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 0x00000000541cca20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000541cca20>
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 0x000000005471f408>
key = (((True, True, True, False, False, 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 0x000000005471f408>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000005471f408>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000005471f408>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000542186e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004349e138>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000005471f980>, <W_TypeObject 'GenericAlias' at 0x50487c90>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x481d4e90>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x481d4e90>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x481d4e90>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x481d4e90>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3e1d39f0>>
w_obj = <W_TypeObject 'ellipsis' at 0x481d4e90>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x481d4e90>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3e1d39f0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x481d4e90>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3e1d39f0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3e1d39f0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3e1d39f0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000052d85268>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004d8c1df8>
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 0x0000000052446960>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000052446960>
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 0x0000000047a85168>
key = (((True, True, True, False, False, 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 0x0000000047a85168>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000047a85168>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000047a85168>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000052447b20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000048fa24b8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000047a856e0>, <W_TypeObject 'GenericAlias' at 0x41b3b4b0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x42e006e8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x42e006e8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x42e006e8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x42e006e8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3a357510>>
w_obj = <W_TypeObject 'ellipsis' at 0x42e006e8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x42e006e8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3a357510>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x42e006e8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3a357510>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3a357510>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3a357510>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004851cd40>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x00000000460bc110>
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 0x00000000481f6320>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000481f6320>
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 0x0000000050ae9398>
key = (((True, True, True, False, False, 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 0x0000000050ae9398>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000050ae9398>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000050ae9398>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000481f7960>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004d3979b8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000050ae9910>, <W_TypeObject 'GenericAlias' at 0x54a28410>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x549bdcc8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x549bdcc8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x549bdcc8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x549bdcc8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4b9ddca0>>
w_obj = <W_TypeObject 'ellipsis' at 0x549bdcc8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x549bdcc8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4b9ddca0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x549bdcc8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4b9ddca0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4b9ddca0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4b9ddca0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004ef3edb8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x00000000524d5da8>
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 0x0000000042b58620>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000042b58620>
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 0x0000000042b38560>
key = (((True, True, True, False, False, 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 0x0000000042b38560>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000042b38560>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000042b38560>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000042b598a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004e44f440>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000042b38ad8>, <W_TypeObject 'GenericAlias' at 0x41944b10>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4f079360>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4f079360>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4f079360>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4f079360>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43094ed0>>
w_obj = <W_TypeObject 'ellipsis' at 0x4f079360>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4f079360>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43094ed0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4f079360>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43094ed0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43094ed0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x43094ed0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000041d50d40>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000005098b628>
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 0x0000000048ab5f20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000048ab5f20>
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 0x0000000054999948>
key = (((True, True, True, False, False, 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 0x0000000054999948>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000054999948>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000054999948>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000046f50fe0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000005116d830>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000054999ec0>, <W_TypeObject 'GenericAlias' at 0x4c66d600>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4e21b830>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4e21b830>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4e21b830>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4e21b830>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3f1e3f50>>
w_obj = <W_TypeObject 'ellipsis' at 0x4e21b830>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4e21b830>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3f1e3f50>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4e21b830>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3f1e3f50>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3f1e3f50>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3f1e3f50>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004af0d358>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000053b34480>
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 0x00000000474e9be0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000474e9be0>
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 0x00000000519988e0>
key = (((True, True, True, False, False, 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 0x00000000519988e0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000519988e0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000519988e0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000051964ea0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004e819da8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000051998e58>, <W_TypeObject 'GenericAlias' at 0x4ede1ec0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4edce608>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4edce608>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4edce608>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4edce608>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x5546c620>>
w_obj = <W_TypeObject 'ellipsis' at 0x4edce608>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4edce608>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x5546c620>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4edce608>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x5546c620>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x5546c620>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x5546c620>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x00000000460fd8f8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000056410610>
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 0x0000000056417720>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000056417720>
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 0x0000000054e859f0>
key = (((True, True, True, False, False, 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 0x0000000054e859f0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000054e859f0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000054e859f0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000054a6e860>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000054d7d9f0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000054e85f68>, <W_TypeObject 'GenericAlias' at 0x55d0e3d8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x563aa800>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x563aa800>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x563aa800>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x563aa800>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x457be160>>
w_obj = <W_TypeObject 'ellipsis' at 0x563aa800>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x563aa800>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x457be160>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x563aa800>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x457be160>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x457be160>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x457be160>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000044f5b358>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000041ac1880>
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 0x000000004338f820>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004338f820>
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 0x00000000445a1868>
key = (((True, True, True, False, False, 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 0x00000000445a1868>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000445a1868>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000445a1868>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004344d9a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004583cbb8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000445a1de0>, <W_TypeObject 'GenericAlias' at 0x49fb2170>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a092ad8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a092ad8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a092ad8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a092ad8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4768f720>>
w_obj = <W_TypeObject 'ellipsis' at 0x4a092ad8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4a092ad8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4768f720>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4a092ad8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4768f720>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4768f720>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4768f720>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000050a243e0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000003d41d948>
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 0x0000000042753920>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000042753920>
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 0x00000000526cbad0>
key = (((True, True, True, False, False, 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 0x00000000526cbad0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000526cbad0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000526cbad0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000042705460>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000005403fcc8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000526e6090>, <W_TypeObject 'GenericAlias' at 0x51fd9520>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4fb35520>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4fb35520>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4fb35520>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4fb35520>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x36246680>>
w_obj = <W_TypeObject 'ellipsis' at 0x4fb35520>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4fb35520>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x36246680>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4fb35520>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x36246680>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x36246680>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x36246680>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000043433d30>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000043266d40>
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 0x0000000048dae220>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000048dae220>
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 0x0000000044b8be88>
key = (((True, True, True, False, False, 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 0x0000000044b8be88>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000044b8be88>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000044b8be88>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000048dafb60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000536005d0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000051886448>, <W_TypeObject 'GenericAlias' at 0x46c38138>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48b9fe18>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48b9fe18>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48b9fe18>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48b9fe18>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x50b7d180>>
w_obj = <W_TypeObject 'ellipsis' at 0x48b9fe18>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x48b9fe18>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x50b7d180>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x48b9fe18>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x50b7d180>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x50b7d180>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x50b7d180>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004af65b50>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000045a20908>
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 0x00000000526177e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000526177e0>
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 0x00000000487cb8d8>
key = (((True, True, True, False, False, 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 0x00000000487cb8d8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000487cb8d8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000487cb8d8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000525acba0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000044f75018>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000487cbe50>, <W_TypeObject 'GenericAlias' at 0x51156138>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4e21bc20>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4e21bc20>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4e21bc20>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4e21bc20>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4fdfbd30>>
w_obj = <W_TypeObject 'ellipsis' at 0x4e21bc20>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4e21bc20>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4fdfbd30>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4e21bc20>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4fdfbd30>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4fdfbd30>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4fdfbd30>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000051220db8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000049aec5e8>
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 0x0000000050af7120>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000050af7120>
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 0x000000004c878cd0>
key = (((True, True, True, False, False, 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 0x000000004c878cd0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004c878cd0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004c878cd0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000538322e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000524c2db0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000004c879248>, <W_TypeObject 'GenericAlias' at 0x42c1b7c0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47239440>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47239440>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47239440>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47239440>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x35ad0740>>
w_obj = <W_TypeObject 'ellipsis' at 0x47239440>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x47239440>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x35ad0740>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x47239440>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x35ad0740>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x35ad0740>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x35ad0740>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004f03edb8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004da61600>
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 0x0000000050ee9c20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000050ee9c20>
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 0x000000004d8e1b40>
key = (((True, True, True, False, False, 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 0x000000004d8e1b40>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004d8e1b40>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004d8e1b40>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004d107060>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000055e934e8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000040de6100>, <W_TypeObject 'GenericAlias' at 0x53236b48>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4e9c3558>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4e9c3558>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4e9c3558>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4e9c3558>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4cbeac40>>
w_obj = <W_TypeObject 'ellipsis' at 0x4e9c3558>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4e9c3558>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4cbeac40>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4e9c3558>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4cbeac40>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4cbeac40>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4cbeac40>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004ef775b0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000045184840>
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 0x000000004b7627a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004b7627a0>
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 0x000000004b265fa0>
key = (((True, True, True, False, False, 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 0x000000004b265fa0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004b265fa0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004b265fa0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004b7638a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004f282100>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000498b4560>, <W_TypeObject 'GenericAlias' at 0x51103600>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x510cfb78>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x510cfb78>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x510cfb78>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x510cfb78>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x554c0d00>>
w_obj = <W_TypeObject 'ellipsis' at 0x510cfb78>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x510cfb78>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x554c0d00>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x510cfb78>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x554c0d00>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x554c0d00>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x554c0d00>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000041d50f98>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000053431100>
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 0x000000004f5f33a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004f5f33a0>
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 0x000000004f5e0608>
key = (((True, True, True, False, False, 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 0x000000004f5e0608>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004f5e0608>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004f5e0608>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004f18eb60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004ca8d4b0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004f5e0b80>, <W_TypeObject 'GenericAlias' at 0x44d271d8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48c08a68>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48c08a68>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48c08a68>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48c08a68>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x39b5a610>>
w_obj = <W_TypeObject 'ellipsis' at 0x48c08a68>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x48c08a68>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x39b5a610>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x48c08a68>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x39b5a610>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x39b5a610>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x39b5a610>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004af0cd40>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000052aa3880>
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 0x0000000047380de0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000047380de0>
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 0x000000004700af00>
key = (((True, True, True, False, False, 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 0x000000004700af00>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004700af00>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004700af00>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004751a0e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000474dfc20>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000004700b478>, <W_TypeObject 'GenericAlias' at 0x4ad52950>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x440fc138>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x440fc138>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x440fc138>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x440fc138>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x44b34c80>>
w_obj = <W_TypeObject 'ellipsis' at 0x440fc138>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x440fc138>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x44b34c80>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x440fc138>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x44b34c80>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x44b34c80>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x44b34c80>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000055cef6a0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000054759240>
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 0x0000000055d54460>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000055d54460>
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 0x0000000055d56ad8>
key = (((True, True, True, False, False, 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 0x0000000055d56ad8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000055d56ad8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000055d56ad8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000055d55b60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004853a5d0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000055d57050>, <W_TypeObject 'GenericAlias' at 0x5594e598>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x516ade88>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x516ade88>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x516ade88>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x516ade88>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4e18b010>>
w_obj = <W_TypeObject 'ellipsis' at 0x516ade88>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x516ade88>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4e18b010>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x516ade88>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4e18b010>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4e18b010>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4e18b010>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004465e5c0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000054f63010>
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 0x00000000559048a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000559048a0>
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 0x0000000054f65d00>
key = (((True, True, True, False, False, 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 0x0000000054f65d00>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000054f65d00>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000054f65d00>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000550cc3e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000519403a0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000054f9c2c0>, <W_TypeObject 'GenericAlias' at 0x528ec560>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x53945210>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x53945210>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x53945210>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x53945210>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46eaa460>>
w_obj = <W_TypeObject 'ellipsis' at 0x53945210>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x53945210>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46eaa460>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x53945210>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46eaa460>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46eaa460>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46eaa460>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000005440f100>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x00000000404ffc90>
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 0x0000000045b93d20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000045b93d20>
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 0x000000004bad98a0>
key = (((True, True, True, False, False, 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 0x000000004bad98a0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004bad98a0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004bad98a0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000045bad720>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004c60f638>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000004bb00058>, <W_TypeObject 'GenericAlias' at 0x42684480>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x42506100>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x42506100>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x42506100>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x42506100>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3f540f30>>
w_obj = <W_TypeObject 'ellipsis' at 0x42506100>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x42506100>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3f540f30>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x42506100>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3f540f30>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3f540f30>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3f540f30>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x00000000423d0110>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000003d54c868>
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 0x00000000418dace0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000418dace0>
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 0x000000004c32cd08>
key = (((True, True, True, False, False, 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 0x000000004c32cd08>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004c32cd08>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004c32cd08>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000489ae0a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000051625e50>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004c32d280>, <W_TypeObject 'GenericAlias' at 0x46b75bb0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x420ee0c8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x420ee0c8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x420ee0c8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x420ee0c8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4f711350>>
w_obj = <W_TypeObject 'ellipsis' at 0x420ee0c8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x420ee0c8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4f711350>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x420ee0c8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4f711350>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4f711350>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4f711350>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004a32d4c0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004340fe20>
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 0x0000000048aa1de0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000048aa1de0>
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 0x000000004904cfe0>
key = (((True, True, True, False, False, 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 0x000000004904cfe0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004904cfe0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004904cfe0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004813fa60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000523a5b08>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000004904d168>, <W_TypeObject 'GenericAlias' at 0x443231d8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5095b9f0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5095b9f0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5095b9f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x5095b9f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4cb66120>>
w_obj = <W_TypeObject 'ellipsis' at 0x5095b9f0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x5095b9f0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4cb66120>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x5095b9f0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4cb66120>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4cb66120>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4cb66120>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004f28e368>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x00000000468ae430>
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 0x000000004a7f2c20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004a7f2c20>
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 0x000000004b847fa0>
key = (((True, True, True, False, False, 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 0x000000004b847fa0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004b847fa0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004b847fa0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004a7f3d60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000042618c28>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000424ec560>, <W_TypeObject 'GenericAlias' at 0x54621b78>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44232720>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44232720>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44232720>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44232720>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47c22ce0>>
w_obj = <W_TypeObject 'ellipsis' at 0x44232720>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x44232720>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47c22ce0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x44232720>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47c22ce0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47c22ce0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47c22ce0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x00000000484f69f8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004a106480>
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 0x0000000044441b60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000044441b60>
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 0x000000004d272d78>
key = (((True, True, True, False, False, 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 0x000000004d272d78>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004d272d78>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004d272d78>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000548dafe0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004b4a93d0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004d2732f0>, <W_TypeObject 'GenericAlias' at 0x43ff6598>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x54a0e170>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x54a0e170>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x54a0e170>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x54a0e170>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x457dca50>>
w_obj = <W_TypeObject 'ellipsis' at 0x54a0e170>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x54a0e170>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x457dca50>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x54a0e170>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x457dca50>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x457dca50>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x457dca50>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004ef3f178>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004f6f88e0>
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 0x0000000055f59160>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000055f59160>
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 0x0000000045f23600>
key = (((True, True, True, False, False, 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 0x0000000045f23600>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000045f23600>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000045f23600>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000053eea8e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000047cf1b78>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000045f23b78>, <W_TypeObject 'GenericAlias' at 0x48320b48>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x54149bb0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x54149bb0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x54149bb0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x54149bb0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47ff0a70>>
w_obj = <W_TypeObject 'ellipsis' at 0x54149bb0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x54149bb0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47ff0a70>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x54149bb0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47ff0a70>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47ff0a70>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x47ff0a70>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x00000000520f76a0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004b440ca0>
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 0x000000004e70ebe0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004e70ebe0>
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 0x0000000046dafad0>
key = (((True, True, True, False, False, 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 0x0000000046dafad0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000046dafad0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000046dafad0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000055a5c620>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000052631b78>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000050672090>, <W_TypeObject 'GenericAlias' at 0x4cd87bb0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x525fdb08>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x525fdb08>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x525fdb08>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x525fdb08>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x44c7f340>>
w_obj = <W_TypeObject 'ellipsis' at 0x525fdb08>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x525fdb08>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x44c7f340>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x525fdb08>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x44c7f340>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x44c7f340>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x44c7f340>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x00000000481e9e20>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000005402f1c8>
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 0x000000004dc6a5a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004dc6a5a0>
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 0x000000004dc9f2f0>
key = (((True, True, True, False, False, 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 0x000000004dc9f2f0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004dc9f2f0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004dc9f2f0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000054916760>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000051454020>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000004dc9f868>, <W_TypeObject 'GenericAlias' at 0x4745e598>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47495328>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47495328>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47495328>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x47495328>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d304d40>>
w_obj = <W_TypeObject 'ellipsis' at 0x47495328>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x47495328>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d304d40>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x47495328>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d304d40>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d304d40>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d304d40>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x00000000516e1010>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004c855ec0>
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 0x000000005397e9a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000005397e9a0>
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 0x0000000053995558>
key = (((True, True, True, False, False, 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 0x0000000053995558>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000053995558>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000053995558>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000005397f8e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000054281a60>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000053995ad0>, <W_TypeObject 'GenericAlias' at 0x4ed7d210>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4ec1d868>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4ec1d868>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4ec1d868>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4ec1d868>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45634230>>
w_obj = <W_TypeObject 'ellipsis' at 0x4ec1d868>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4ec1d868>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45634230>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4ec1d868>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45634230>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45634230>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45634230>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000044604638>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x00000000548a9d80>
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 0x0000000051a4f4a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000051a4f4a0>
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 0x0000000055b6ea68>
key = (((True, True, True, False, False, 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 0x0000000055b6ea68>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000055b6ea68>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000055b6ea68>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000005574c660>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004d6c8c60>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000055b6efe0>, <W_TypeObject 'GenericAlias' at 0x4b2c1750>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b2f5f68>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b2f5f68>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b2f5f68>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b2f5f68>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x5084d5f0>>
w_obj = <W_TypeObject 'ellipsis' at 0x4b2f5f68>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4b2f5f68>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x5084d5f0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4b2f5f68>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x5084d5f0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x5084d5f0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x5084d5f0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000056b73358>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000056fed4e8>
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 0x0000000044d98e60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000044d98e60>
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 0x0000000041242138>
key = (((True, True, True, False, False, 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 0x0000000041242138>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000041242138>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000041242138>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004ce74060>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000041ef6b10>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000412426b0>, <W_TypeObject 'GenericAlias' at 0x42643ad0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4e52f4b0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4e52f4b0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4e52f4b0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4e52f4b0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4f9be420>>
w_obj = <W_TypeObject 'ellipsis' at 0x4e52f4b0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4e52f4b0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4f9be420>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4e52f4b0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4f9be420>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4f9be420>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4f9be420>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000050a249f8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000003fe31d58>
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 0x00000000463e8360>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000463e8360>
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 0x000000004bd038a0>
key = (((True, True, True, False, False, 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 0x000000004bd038a0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004bd038a0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004bd038a0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000464125a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004d3b3050>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000004bd03e18>, <W_TypeObject 'GenericAlias' at 0x43f0b168>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4d82fbb0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4d82fbb0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4d82fbb0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4d82fbb0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3c883f00>>
w_obj = <W_TypeObject 'ellipsis' at 0x4d82fbb0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4d82fbb0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3c883f00>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4d82fbb0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3c883f00>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3c883f00>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3c883f00>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x00000000458d76a0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000003fb6d998>
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 0x0000000044aed960>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000044aed960>
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 0x00000000525166e8>
key = (((True, True, True, False, False, 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 0x00000000525166e8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000525166e8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000525166e8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000041ca8b20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000048881638>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000052516c60>, <W_TypeObject 'GenericAlias' at 0x4d7269f8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4f119050>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4f119050>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4f119050>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4f119050>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4ca4b3d0>>
w_obj = <W_TypeObject 'ellipsis' at 0x4f119050>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4f119050>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4ca4b3d0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4f119050>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4ca4b3d0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4ca4b3d0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4ca4b3d0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004f221c40>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000043542f20>
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 0x00000000475914e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000475914e0>
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 0x0000000041e97b08>
key = (((True, True, True, False, False, 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 0x0000000041e97b08>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000041e97b08>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000041e97b08>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000446d49a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004b086988>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000041e7e0c8>, <W_TypeObject 'GenericAlias' at 0x4cc02f70>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a917c20>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a917c20>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a917c20>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a917c20>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x55fd56a0>>
w_obj = <W_TypeObject 'ellipsis' at 0x4a917c20>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4a917c20>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x55fd56a0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4a917c20>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x55fd56a0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x55fd56a0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x55fd56a0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x00000000484f69f8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000045f7cac0>
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 0x00000000452445e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000452445e0>
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 0x0000000048fa3638>
key = (((True, True, True, False, False, 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 0x0000000048fa3638>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000048fa3638>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000048fa3638>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000045245a60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004bdc7c90>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000048fa3bb0>, <W_TypeObject 'GenericAlias' at 0x430da950>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4bf9e598>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4bf9e598>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4bf9e598>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4bf9e598>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x457cace0>>
w_obj = <W_TypeObject 'ellipsis' at 0x4bf9e598>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4bf9e598>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x457cace0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4bf9e598>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x457cace0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x457cace0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x457cace0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000054e943e0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004a0cc368>
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 0x0000000053832560>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000053832560>
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 0x0000000042d10560>
key = (((True, True, True, False, False, 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 0x0000000042d10560>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000042d10560>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000042d10560>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000538339a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000548f8678>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000042d10ad8>, <W_TypeObject 'GenericAlias' at 0x4f3409f8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x50a1a7c8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x50a1a7c8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x50a1a7c8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x50a1a7c8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46b83880>>
w_obj = <W_TypeObject 'ellipsis' at 0x50a1a7c8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x50a1a7c8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46b83880>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x50a1a7c8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46b83880>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46b83880>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46b83880>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004e7bef98>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004ec2d740>
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 0x0000000050c48220>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000050c48220>
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 0x0000000050182e58>
key = (((True, True, True, False, False, 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 0x0000000050182e58>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000050182e58>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000050182e58>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000041db0560>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000052cb1210>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000501833d0>, <W_TypeObject 'GenericAlias' at 0x4ade09c0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4ada5d70>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4ada5d70>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4ada5d70>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4ada5d70>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d425dc0>>
w_obj = <W_TypeObject 'ellipsis' at 0x4ada5d70>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4ada5d70>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d425dc0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4ada5d70>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d425dc0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d425dc0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4d425dc0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000054d5c980>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000004f2e2638>
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 0x000000004a8073a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004a8073a0>
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 0x000000004aa5cbb8>
key = (((True, True, True, False, False, 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 0x000000004aa5cbb8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004aa5cbb8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004aa5cbb8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004a80c8e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000416d8fa8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004aa5d130>, <W_TypeObject 'GenericAlias' at 0x547923a0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44f32720>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44f32720>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44f32720>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44f32720>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x454e4c00>>
w_obj = <W_TypeObject 'ellipsis' at 0x44f32720>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x44f32720>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x454e4c00>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x44f32720>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x454e4c00>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x454e4c00>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x454e4c00>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x000000004ebdfbc8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000005081d178>
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 0x000000004845c7a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004845c7a0>
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 0x00000000484ae950>
key = (((True, True, True, False, False, 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 0x00000000484ae950>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000484ae950>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000484ae950>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004845d8e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000051b1e8a8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000484aeec8>, <W_TypeObject 'GenericAlias' at 0x555971d8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48a52d08>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48a52d08>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48a52d08>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48a52d08>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x554be8a0>>
w_obj = <W_TypeObject 'ellipsis' at 0x48a52d08>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x48a52d08>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x554be8a0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x48a52d08>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x554be8a0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x554be8a0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x554be8a0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000046ad9808>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x00000000467d28e0>
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 0x0000000053b5f6e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000053b5f6e0>
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 0x0000000055972528>
key = (((True, True, True, False, False, 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 0x0000000055972528>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000055972528>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000055972528>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000005129c8a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000050f86560>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000055972aa0>, <W_TypeObject 'GenericAlias' at 0x44f89948>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x506d1c20>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x506d1c20>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x506d1c20>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x506d1c20>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x55471290>>
w_obj = <W_TypeObject 'ellipsis' at 0x506d1c20>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x506d1c20>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x55471290>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x506d1c20>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x55471290>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x55471290>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x55471290>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000050412818>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000054614020>
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 0x000000004e2fd5a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004e2fd5a0>
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 0x000000004e30dc20>
key = (((True, True, True, False, False, 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 0x000000004e30dc20>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004e30dc20>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004e30dc20>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004965e7a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000046728aa0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000539d21e0>, <W_TypeObject 'GenericAlias' at 0x51a6c950>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x51a61168>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x51a61168>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x51a61168>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x51a61168>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46c1fd80>>
w_obj = <W_TypeObject 'ellipsis' at 0x51a61168>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x51a61168>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46c1fd80>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x51a61168>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46c1fd80>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46c1fd80>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46c1fd80>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x0000000046538188>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000056863b50>
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 0x00000000567401a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000567401a0>
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 0x00000000567389f8>
key = (((True, True, True, False, False, 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 0x00000000567389f8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000567389f8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000567389f8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000567406e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004345e410>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000056738f70>, <W_TypeObject 'GenericAlias' at 0x44d9aec8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x528ece20>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x528ece20>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x528ece20>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x528ece20>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3c06c280>>
w_obj = <W_TypeObject 'ellipsis' at 0x528ece20>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x528ece20>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3c06c280>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x528ece20>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3c06c280>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3c06c280>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3c06c280>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, 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 0x00000000555d6278>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8d0efd70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x000000002dc073e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002ccf2c20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ccf2c60>]
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 0x0000000041ac0660>
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 0x0000000044cb6b60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000044cb6b60>
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 0x000000004a637360>
key = (((True, True, True, False, False, 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 0x000000004a637360>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004a637360>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004a637360>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000044ce74e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004bf35600>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2ddb0>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff89e2ddf0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff89e2de08>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000032490cd0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000004a6378d8>, <W_TypeObject 'GenericAlias' at 0x43b962f8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x40e54e58>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x40e54e58>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x40e54e58>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x40e54e58>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x55490ed0>>
w_obj = <W_TypeObject 'ellipsis' at 0x40e54e58>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x40e54e58>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x55490ed0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x40e54e58>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x55490ed0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x55490ed0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x55490ed0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError
============= 335 passed, 9 skipped, 124 error in 1202.59 seconds ==============
++ 02:52:46 starting module/atexit/test [41 started in total]
__ module/_socket/test [38 done in total, somefailed=False] ___________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 87 items
module/_socket/test/apptest_socket.py .....................ss..................s................s...
module/_socket/test/test_sock_app.py ........................
module/_socket/test/test_ztranslation.py .
==================== 83 passed, 4 skipped in 284.35 seconds ====================
++ 02:53:15 starting module/binascii/test [42 started in total]
__ module/atexit/test [39 done in total, somefailed=False] ____________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 2 items
module/atexit/test/apptest_atexit.py ..
========================== 2 passed in 27.83 seconds ===========================
++ 02:53:19 starting module/bz2/test [43 started in total]
__ module/_weakref/test [40 done in total, somefailed=False] __________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 43 items
module/_weakref/test/apptest_weakref.py ...........................................
========================== 43 passed in 88.78 seconds ==========================
++ 02:53:37 starting module/cmath/test [44 started in total]
__ module/binascii/test [41 done in total, somefailed=False] __________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 18 items
module/binascii/test/test_binascii.py ..................
========================== 18 passed in 35.00 seconds ==========================
++ 02:53:53 starting module/cpyext/test/test_api.py [45 started in total]
__ module/cmath/test [42 done in total, somefailed=False] _____________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 18 items
module/cmath/test/test_cmath.py ..................
========================== 18 passed in 19.21 seconds ==========================
++ 02:53:58 starting module/cpyext/test/test_arraymodule.py [46 started in total]
__ module/cpyext/test/test_api.py [43 done in total, somefailed=True] _________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 0x45932b80>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x460d0f80>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 20.41 seconds ======================
++ 02:54:37 starting module/cpyext/test/test_async_iter.py [47 started in total]
__ module/array/test [44 done in total, somefailed=False] _____________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 184.60 seconds ====================
++ 02:55:26 starting module/cpyext/test/test_boolobject.py [48 started in total]
__ module/cpyext/test/test_async_iter.py [45 done in total, somefailed=True] __
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 0x000000002b99a818>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffffa7595d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ac2e060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000025028c60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000025028ca0>]
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 0x000000002ac2e060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000025028c60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000025028ca0>]
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 0x000000002b9ca160>
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 0x000000002b8080a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000002b8080a0>
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 0x000000002b9e0950>
key = (((True, True, True, False, False, 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 0x000000002b9e0950>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000002b9e0950>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000002b9e0950>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000286787e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002c8f4a30>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa8cb3dc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffffa8cb3e08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa8cb3e20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000292e2410>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000002b9e0ec8>, <W_TypeObject 'GenericAlias' at 0x2cf9b8a0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2d511910>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2d511910>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2d511910>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2d511910>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x283ca780>>
w_obj = <W_TypeObject 'ellipsis' at 0x2d511910>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x2d511910>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x283ca780>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x2d511910>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x283ca780>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x283ca780>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x283ca780>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000002eb6a2f0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffffa7595d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ac2e060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000025028c60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000025028ca0>]
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 0x000000002ac2e060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000025028c60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000025028ca0>]
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 0x000000002ebaa458>
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 0x000000002eb5c1a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000002eb5c1a0>
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 0x000000002eb4d788>
key = (((True, True, True, False, False, 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 0x000000002eb4d788>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000002eb4d788>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000002eb4d788>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000002a19a720>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000029aae800>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa8cb3dc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffffa8cb3e08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa8cb3e20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000292e2410>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000002eb4dd00>, <W_TypeObject 'GenericAlias' at 0x2c3c9ef8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2b822058>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2b822058>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2b822058>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2b822058>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x29e0e2d0>>
w_obj = <W_TypeObject 'ellipsis' at 0x2b822058>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x2b822058>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x29e0e2d0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x2b822058>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x29e0e2d0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x29e0e2d0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x29e0e2d0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000002ca85bc8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffffa7595d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002ac2e060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000025028c60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000025028ca0>]
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 0x000000002ac2e060>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000025028c60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000025028ca0>]
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 0x000000002bba90d8>
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 0x000000002ee34760>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000002ee34760>
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 0x000000002ee8e3a0>
key = (((True, True, True, False, False, 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 0x000000002ee8e3a0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000002ee8e3a0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000002ee8e3a0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000002f0b36a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002f0f3fa0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa8cb3dc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffffa8cb3e08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa8cb3e20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000292e2410>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000002ee8e918>, <W_TypeObject 'GenericAlias' at 0x2f423558>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2f48fc20>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2f48fc20>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2f48fc20>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2f48fc20>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24e34ac0>>
w_obj = <W_TypeObject 'ellipsis' at 0x2f48fc20>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x2f48fc20>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24e34ac0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x2f48fc20>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24e34ac0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24e34ac0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24e34ac0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 29.35 seconds ===========================
++ 02:55:28 starting module/cpyext/test/test_borrow.py [49 started in total]
__ module/bz2/test [46 done in total, somefailed=False] _______________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 163.97 seconds ====================
++ 02:56:05 starting module/cpyext/test/test_buffer.py [50 started in total]
__ module/cpyext/test/test_borrow.py [47 done in total, somefailed=True] ______
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 0x000000002d649c40>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff902a5d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002bb76920>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000027804ce0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000027804d20>]
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 0x000000002bb76920>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000027804ce0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000027804d20>]
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 0x000000002e5b3bc8>
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 0x000000002d6b48e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000002d6b48e0>
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 0x000000002e5b7750>
key = (((True, True, True, False, False, 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 0x000000002e5b7750>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000002e5b7750>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000002e5b7750>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000002f0a0060>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002f1d3d70>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff8ef7ddd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff8ef7de18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff8ef7de30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000002ba9c608>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000002e5b7cc8>, <W_TypeObject 'GenericAlias' at 0x2f92ecd0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2feed638>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2feed638>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2feed638>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2feed638>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2d838c70>>
w_obj = <W_TypeObject 'ellipsis' at 0x2feed638>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x2feed638>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2d838c70>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x2feed638>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2d838c70>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2d838c70>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2d838c70>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000000031074f98>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff902a5d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002bb76920>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000027804ce0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000027804d20>]
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 0x000000002bb76920>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000027804ce0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000027804d20>]
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 0x000000002ef7c4d0>
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 0x000000002efa6060>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000002efa6060>
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 0x000000002ef783d8>
key = (((True, True, True, False, False, 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 0x000000002ef783d8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000002ef783d8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000002ef783d8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000002bb9df20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002c22d478>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff8ef7ddd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff8ef7de18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff8ef7de30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000002ba9c608>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000002ef78950>, <W_TypeObject 'GenericAlias' at 0x2d22fb08>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2ee7b558>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2ee7b558>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2ee7b558>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2ee7b558>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2db4ed20>>
w_obj = <W_TypeObject 'ellipsis' at 0x2ee7b558>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x2ee7b558>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2db4ed20>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x2ee7b558>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2db4ed20>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2db4ed20>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2db4ed20>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00000000307ea110>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff902a5d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002bb76920>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000027804ce0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000027804d20>]
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 0x000000002bb76920>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000027804ce0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000027804d20>]
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 0x000000002c9bb2e0>
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 0x00000000308a92a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000308a92a0>
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 0x000000003091a560>
key = (((True, True, True, False, False, 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 0x000000003091a560>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000003091a560>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000003091a560>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000031ae35e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000031bf6218>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff8ef7ddd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff8ef7de18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff8ef7de30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000002ba9c608>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000003091aad8>, <W_TypeObject 'GenericAlias' at 0x31ef0800>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x31f57d70>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x31f57d70>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x31f57d70>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x31f57d70>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2e18bdf0>>
w_obj = <W_TypeObject 'ellipsis' at 0x31f57d70>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x31f57d70>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2e18bdf0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x31f57d70>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2e18bdf0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2e18bdf0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2e18bdf0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 29.38 seconds ===========================
++ 02:56:19 starting module/cpyext/test/test_bytearrayobject.py [51 started in total]
__ module/cpyext/test/test_boolobject.py [48 done in total, somefailed=True] __
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 0x1a6c53e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000001e9cc278>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffffb89d3d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000019f912e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000149d4d20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000149d4d60>]
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 0x0000000019f912e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000149d4d20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000149d4d60>]
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 0x000000001ea0d740>
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 0x000000001e9e21e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000001e9e21e0>
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 0x000000001e9b9360>
key = (((True, True, True, False, False, 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 0x000000001e9b9360>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000001e9b9360>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000001e9b9360>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000019fa2d60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000019d04758>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffb76aadd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffffb76aae18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffb76aae30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000018b0b4b0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000001e9b98d8>, <W_TypeObject 'GenericAlias' at 0x1b0a3948>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b396838>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b396838>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b396838>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b396838>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1568ed20>>
w_obj = <W_TypeObject 'ellipsis' at 0x1b396838>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1b396838>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1568ed20>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1b396838>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1568ed20>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1568ed20>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1568ed20>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000000019961268>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffffb89d3d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000019f912e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000149d4d20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000149d4d60>]
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 0x0000000019f912e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000149d4d20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000149d4d60>]
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 0x000000001c13c9f8>
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 0x000000001cf9dea0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000001cf9dea0>
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 0x000000001cfaaec8>
key = (((True, True, True, False, False, 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 0x000000001cfaaec8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000001cfaaec8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000001cfaaec8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000001c65ba60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001c4fe8e0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffb76aadd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffffb76aae18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffb76aae30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000018b0b4b0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000001cfab440>, <W_TypeObject 'GenericAlias' at 0x1d5a66e8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d5fb980>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d5fb980>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d5fb980>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d5fb980>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x15f30e60>>
w_obj = <W_TypeObject 'ellipsis' at 0x1d5fb980>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1d5fb980>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x15f30e60>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1d5fb980>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x15f30e60>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x15f30e60>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x15f30e60>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000001f3cee30>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffffb89d3d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000019f912e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000149d4d20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000149d4d60>]
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 0x0000000019f912e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000149d4d20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000149d4d60>]
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 0x000000001fc80fc0>
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 0x000000001fc5c460>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000001fc5c460>
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 0x000000001fcc8170>
key = (((True, True, True, False, False, 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 0x000000001fcc8170>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000001fcc8170>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000001fcc8170>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000001fdf3260>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001fe625d0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffb76aadd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffffb76aae18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffb76aae30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000018b0b4b0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000001fcc86e8>, <W_TypeObject 'GenericAlias' at 0x20161788>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2033cfa8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2033cfa8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2033cfa8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2033cfa8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1a55f200>>
w_obj = <W_TypeObject 'ellipsis' at 0x2033cfa8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x2033cfa8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1a55f200>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x2033cfa8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1a55f200>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1a55f200>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1a55f200>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 37.09 seconds ===========================
++ 02:56:24 starting module/cpyext/test/test_bytesobject.py [52 started in total]
__ module/cpyext/test/test_arraymodule.py [49 done in total, somefailed=True] _
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 0x0000000012bdd1f0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff94dc5d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x000000001402ec78>
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 0x00000000140463a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000140463a0>
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 0x000000001406f210>
key = (((True, True, True, False, False, 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 0x000000001406f210>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000001406f210>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000001406f210>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000012458420>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000010995130>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9ddc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff93a9de08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9de20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000011589f30>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000001406f788>, <W_TypeObject 'GenericAlias' at 0x14f7f0c0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x155a7478>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x155a7478>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x155a7478>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x155a7478>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1303c7f0>>
w_obj = <W_TypeObject 'ellipsis' at 0x155a7478>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x155a7478>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1303c7f0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x155a7478>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1303c7f0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1303c7f0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1303c7f0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00000000174c62f0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff94dc5d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x000000001757f1f0>
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 0x00000000174de260>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000174de260>
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 0x0000000012aee800>
key = (((True, True, True, False, False, 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 0x0000000012aee800>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000012aee800>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000012aee800>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000148a07e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000011f3dda8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9ddc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff93a9de08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9de20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000011589f30>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000012aef1d8>, <W_TypeObject 'GenericAlias' at 0x134ee218>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x13f0d1a0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x13f0d1a0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x13f0d1a0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x13f0d1a0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1408b8a0>>
w_obj = <W_TypeObject 'ellipsis' at 0x13f0d1a0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x13f0d1a0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1408b8a0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x13f0d1a0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1408b8a0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1408b8a0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1408b8a0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000000014617cb8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff94dc5d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000014bf3538>
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 0x00000000173695a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000173695a0>
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 0x0000000017101ec0>
key = (((True, True, True, False, False, 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 0x0000000017101ec0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000017101ec0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000017101ec0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000016723b60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001674b7c0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9ddc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff93a9de08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9de20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000011589f30>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000017142480>, <W_TypeObject 'GenericAlias' at 0x178bc528>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1782bb40>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1782bb40>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1782bb40>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1782bb40>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x12a41180>>
w_obj = <W_TypeObject 'ellipsis' at 0x1782bb40>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1782bb40>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x12a41180>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1782bb40>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x12a41180>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x12a41180>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x12a41180>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000001857b8f8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff94dc5d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000018efe390>
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 0x0000000018e9e1a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000018e9e1a0>
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 0x0000000018ea0fa8>
key = (((True, True, True, False, False, 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 0x0000000018ea0fa8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000018ea0fa8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000018ea0fa8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000019021ae0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000019091980>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9ddc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff93a9de08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9de20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000011589f30>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000018ea1520>, <W_TypeObject 'GenericAlias' at 0x193a8448>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1942eb80>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1942eb80>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1942eb80>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1942eb80>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1940a500>>
w_obj = <W_TypeObject 'ellipsis' at 0x1942eb80>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1942eb80>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1940a500>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1942eb80>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1940a500>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1940a500>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1940a500>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00000000133b0200>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff94dc5d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000011d1a8e0>
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 0x0000000015c2b220>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000015c2b220>
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 0x0000000012f436e0>
key = (((True, True, True, False, False, 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 0x0000000012f436e0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000012f436e0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000012f436e0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000013993fa0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000014c87980>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9ddc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff93a9de08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9de20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000011589f30>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000012f43c58>, <W_TypeObject 'GenericAlias' at 0x175fc410>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x176a7130>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x176a7130>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x176a7130>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x176a7130>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x142653e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x176a7130>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x176a7130>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x142653e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x176a7130>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x142653e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x142653e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x142653e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000000012d54b60>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff94dc5d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x00000000144715b0>
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 0x0000000015a37ca0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000015a37ca0>
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 0x0000000016124aa0>
key = (((True, True, True, False, False, 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 0x0000000016124aa0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000016124aa0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000016124aa0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000017963820>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000016c05b78>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9ddc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff93a9de08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9de20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000011589f30>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000016125018>, <W_TypeObject 'GenericAlias' at 0x179b5c90>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x186529f8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x186529f8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x186529f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x186529f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xd1269e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x186529f8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x186529f8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xd1269e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x186529f8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xd1269e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xd1269e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xd1269e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000001244c368>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff94dc5d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x00000000180903e0>
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 0x000000001820f8e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000001820f8e0>
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 0x000000001824b7f8>
key = (((True, True, True, False, False, 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 0x000000001824b7f8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000001824b7f8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000001824b7f8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000173a1420>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000016609b40>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9ddc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff93a9de08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9de20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000011589f30>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000001824bd70>, <W_TypeObject 'GenericAlias' at 0x184eadb0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x172cd9b8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x172cd9b8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x172cd9b8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x172cd9b8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13a2c7e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x172cd9b8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x172cd9b8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13a2c7e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x172cd9b8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13a2c7e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13a2c7e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13a2c7e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000000019fd6980>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff94dc5d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000010de9920>
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 0x0000000014650820>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000014650820>
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 0x0000000013dd9558>
key = (((True, True, True, False, False, 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 0x0000000013dd9558>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000013dd9558>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000013dd9558>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000149598a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000014143830>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9ddc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff93a9de08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9de20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000011589f30>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000013dec528>, <W_TypeObject 'GenericAlias' at 0x1572b718>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x159b0020>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x159b0020>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x159b0020>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x159b0020>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x125b07a0>>
w_obj = <W_TypeObject 'ellipsis' at 0x159b0020>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x159b0020>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x125b07a0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x159b0020>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x125b07a0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x125b07a0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x125b07a0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00000000132a9538>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff94dc5d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000014506070>
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 0x0000000014d046a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000014d046a0>
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 0x0000000014aaf050>
key = (((True, True, True, False, False, 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 0x0000000014aaf050>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000014aaf050>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000014aaf050>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000014d05920>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000017747088>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9ddc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff93a9de08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9de20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000011589f30>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000014aaf5c8>, <W_TypeObject 'GenericAlias' at 0x17260138>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x16db4870>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x16db4870>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x16db4870>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x16db4870>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x19739610>>
w_obj = <W_TypeObject 'ellipsis' at 0x16db4870>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x16db4870>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x19739610>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x16db4870>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x19739610>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x19739610>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x19739610>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000000013da4bd8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff94dc5d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x00000000158331a0>
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 0x00000000189a3220>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000189a3220>
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 0x00000000189c44f0>
key = (((True, True, True, False, False, 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 0x00000000189c44f0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000189c44f0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000189c44f0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000017b586e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000019f151a0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9ddc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff93a9de08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9de20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000011589f30>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000189c4a68>, <W_TypeObject 'GenericAlias' at 0x1634f3d0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1634d788>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1634d788>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1634d788>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1634d788>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x144ce440>>
w_obj = <W_TypeObject 'ellipsis' at 0x1634d788>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1634d788>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x144ce440>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1634d788>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x144ce440>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x144ce440>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x144ce440>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000001a15a110>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff94dc5d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x000000001a1f8700>
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 0x000000001a7b5f20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000001a7b5f20>
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 0x000000001a7baa30>
key = (((True, True, True, False, False, 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 0x000000001a7baa30>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000001a7baa30>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000001a7baa30>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000015c69a60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000100ee138>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9ddc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff93a9de08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9de20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000011589f30>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000001a7bafa8>, <W_TypeObject 'GenericAlias' at 0x137801e0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x13b3cd40>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x13b3cd40>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x13b3cd40>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x13b3cd40>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x12420c00>>
w_obj = <W_TypeObject 'ellipsis' at 0x13b3cd40>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x13b3cd40>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x12420c00>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x13b3cd40>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x12420c00>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x12420c00>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x12420c00>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000001914dc40>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff94dc5d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x000000001366a458>
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 0x00000000176fd5e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000176fd5e0>
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 0x00000000159fa7c8>
key = (((True, True, True, False, False, 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 0x00000000159fa7c8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000159fa7c8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000159fa7c8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000017767320>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000015c109c0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9ddc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff93a9de08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9de20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000011589f30>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000159fad40>, <W_TypeObject 'GenericAlias' at 0x15713cc8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1951a838>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1951a838>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1951a838>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1951a838>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xd2807f0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1951a838>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1951a838>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xd2807f0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1951a838>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xd2807f0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xd2807f0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xd2807f0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000000da9d268>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff94dc5d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000014c42908>
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 0x000000001a5636a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000001a5636a0>
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 0x0000000014933600>
key = (((True, True, True, False, False, 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 0x0000000014933600>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000014933600>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000014933600>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000001472b2e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000145f9050>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9ddc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff93a9de08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9de20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000011589f30>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000014933b78>, <W_TypeObject 'GenericAlias' at 0x14e3b8a0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x17f80480>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x17f80480>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x17f80480>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x17f80480>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1289a920>>
w_obj = <W_TypeObject 'ellipsis' at 0x17f80480>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x17f80480>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1289a920>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x17f80480>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1289a920>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1289a920>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1289a920>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000001a963da8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff94dc5d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000018daf420>
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 0x0000000016a3d2e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000016a3d2e0>
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 0x0000000016a01ec0>
key = (((True, True, True, False, False, 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 0x0000000016a01ec0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000016a01ec0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000016a01ec0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000001619b160>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000017e5e330>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9ddc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff93a9de08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9de20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000011589f30>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000001a0a4480>, <W_TypeObject 'GenericAlias' at 0x15d6f7f8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x189819f0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x189819f0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x189819f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x189819f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xf45daf0>>
w_obj = <W_TypeObject 'ellipsis' at 0x189819f0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x189819f0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xf45daf0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x189819f0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xf45daf0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xf45daf0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xf45daf0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000000016cc2b60>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff94dc5d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x000000001277f240>
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 0x00000000134f96e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000134f96e0>
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 0x00000000140fa9c0>
key = (((True, True, True, False, False, 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 0x00000000140fa9c0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000140fa9c0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000140fa9c0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000013557320>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000011ad7ec0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9ddc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff93a9de08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9de20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000011589f30>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000140faf38>, <W_TypeObject 'GenericAlias' at 0x150e3bb0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x15437fa0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x15437fa0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x15437fa0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x15437fa0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14627a20>>
w_obj = <W_TypeObject 'ellipsis' at 0x15437fa0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x15437fa0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14627a20>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x15437fa0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14627a20>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14627a20>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14627a20>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000000014617da8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff94dc5d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000013359920>
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 0x0000000019a0ae20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000019a0ae20>
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 0x00000000181d8368>
key = (((True, True, True, False, False, 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 0x00000000181d8368>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000181d8368>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000181d8368>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000199a17a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000196bd638>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9ddc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff93a9de08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9de20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000011589f30>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000181d88e0>, <W_TypeObject 'GenericAlias' at 0x182164f0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x181fb440>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x181fb440>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x181fb440>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x181fb440>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13ce5250>>
w_obj = <W_TypeObject 'ellipsis' at 0x181fb440>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x181fb440>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13ce5250>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x181fb440>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13ce5250>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13ce5250>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13ce5250>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000000012038908>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff94dc5d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000013ee4020>
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 0x0000000017dc4160>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000017dc4160>
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 0x0000000016216918>
key = (((True, True, True, False, False, 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 0x0000000016216918>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000016216918>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000016216918>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000017dc5ca0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000172cae90>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9ddc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff93a9de08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9de20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000011589f30>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000016216e90>, <W_TypeObject 'GenericAlias' at 0x158e8fa8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1856e288>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1856e288>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1856e288>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1856e288>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1463f6f0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1856e288>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1856e288>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1463f6f0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1856e288>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1463f6f0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1463f6f0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1463f6f0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000001244c9f8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff94dc5d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000012a8cc60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000d2fcd20>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000d2fcd60>]
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 0x0000000017832ca0>
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 0x000000001aba7460>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000001aba7460>
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 0x000000001abc9f68>
key = (((True, True, True, False, False, 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 0x000000001abc9f68>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000001abc9f68>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000001abc9f68>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000001acaafa0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001b0764f0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9ddc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff93a9de08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff93a9de20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000011589f30>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000001ac62528>, <W_TypeObject 'GenericAlias' at 0x1a3e2c60>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1a411a98>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1a411a98>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1a411a98>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1a411a98>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1067e830>>
w_obj = <W_TypeObject 'ellipsis' at 0x1a411a98>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1a411a98>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1067e830>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1a411a98>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1067e830>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1067e830>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1067e830>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 140.53 seconds ==========================
++ 02:56:37 starting module/cpyext/test/test_capsule.py [53 started in total]
__ module/cpyext/test/test_buffer.py [50 done in total, somefailed=True] ______
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 0x0000000011c2dcb8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff824b1d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000010474460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000ae30ca0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000ae30ce0>]
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 0x0000000010474460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000ae30ca0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000ae30ce0>]
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 0x0000000012166390>
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 0x00000000121782a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000121782a0>
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 0x000000001210e800>
key = (((True, True, True, False, False, 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 0x000000001210e800>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000001210e800>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000001210e800>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000000e4fe4e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000012683da8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff83bcfdc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff83bcfe08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff83bcfe20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000000f0cfa98>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000001210ed78>, <W_TypeObject 'GenericAlias' at 0x12d72b10>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x133ec528>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x133ec528>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x133ec528>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x133ec528>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11877450>>
w_obj = <W_TypeObject 'ellipsis' at 0x133ec528>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x133ec528>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11877450>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x133ec528>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11877450>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11877450>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11877450>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000000010545268>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff824b1d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000010474460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000ae30ca0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000ae30ce0>]
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 0x0000000010474460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000ae30ca0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000ae30ce0>]
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 0x000000000f542e08>
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 0x00000000108428e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000108428e0>
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 0x0000000010988838>
key = (((True, True, True, False, False, 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 0x0000000010988838>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000010988838>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000010988838>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000109c44e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001108ac28>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff83bcfdc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff83bcfe08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff83bcfe20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000000f0cfa98>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000010989b78>, <W_TypeObject 'GenericAlias' at 0x128a13d0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x129271d8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x129271d8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x129271d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x129271d8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xe0ac110>>
w_obj = <W_TypeObject 'ellipsis' at 0x129271d8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x129271d8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xe0ac110>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x129271d8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xe0ac110>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xe0ac110>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xe0ac110>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000000014189718>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff824b1d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000010474460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000ae30ca0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000ae30ce0>]
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 0x0000000010474460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000ae30ca0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000ae30ce0>]
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 0x000000001294a020>
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 0x0000000013d86f20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000013d86f20>
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 0x0000000013d7f9b8>
key = (((True, True, True, False, False, 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 0x0000000013d7f9b8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000013d7f9b8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000013d7f9b8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000144e9b20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000014948250>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff83bcfdc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff83bcfe08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff83bcfe20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000000f0cfa98>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000013d7ff30>, <W_TypeObject 'GenericAlias' at 0x14cbe8a8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x14c912f0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x14c912f0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x14c912f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x14c912f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xe316050>>
w_obj = <W_TypeObject 'ellipsis' at 0x14c912f0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x14c912f0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xe316050>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x14c912f0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xe316050>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xe316050>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xe316050>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00000000154bdbc8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff824b1d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000010474460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000ae30ca0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000ae30ce0>]
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 0x0000000010474460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000ae30ca0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000ae30ce0>]
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 0x00000000162bad40>
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 0x00000000162b8360>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000162b8360>
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 0x00000000162b5590>
key = (((True, True, True, False, False, 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 0x00000000162b5590>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000162b5590>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000162b5590>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000163c0820>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000164a6528>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff83bcfdc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff83bcfe08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff83bcfe20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000000f0cfa98>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000162b5b08>, <W_TypeObject 'GenericAlias' at 0x1674ec28>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x167b5d00>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x167b5d00>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x167b5d00>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x167b5d00>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xe356b20>>
w_obj = <W_TypeObject 'ellipsis' at 0x167b5d00>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x167b5d00>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xe356b20>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x167b5d00>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xe356b20>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xe356b20>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xe356b20>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000000013038e30>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff824b1d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000010474460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000ae30ca0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000ae30ce0>]
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 0x0000000010474460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000ae30ca0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000ae30ce0>]
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 0x000000000f6201d8>
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 0x0000000012756ba0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000012756ba0>
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 0x000000000e106250>
key = (((True, True, True, False, False, 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 0x000000000e106250>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000000e106250>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000000e106250>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000001281d820>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000129591d8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff83bcfdc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff83bcfe08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff83bcfe20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000000f0cfa98>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000000e106bf0>, <W_TypeObject 'GenericAlias' at 0x14a975c8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x14b44d78>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x14b44d78>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x14b44d78>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x14b44d78>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11c1a5d0>>
w_obj = <W_TypeObject 'ellipsis' at 0x14b44d78>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x14b44d78>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11c1a5d0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x14b44d78>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11c1a5d0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11c1a5d0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11c1a5d0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000000010584908>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff824b1d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000010474460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000ae30ca0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000ae30ce0>]
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 0x0000000010474460>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000ae30ca0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000ae30ce0>]
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 0x00000000104f62a0>
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 0x0000000016d5c760>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000016d5c760>
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 0x0000000016d5afe0>
key = (((True, True, True, False, False, 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 0x0000000016d5afe0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000016d5afe0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000016d5afe0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000016d5de20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000015a0b830>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff83bcfdc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff83bcfe08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff83bcfe20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000000f0cfa98>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000016d5b558>, <W_TypeObject 'GenericAlias' at 0x14130d40>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x14a4dcc8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x14a4dcc8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x14a4dcc8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x14a4dcc8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11cb4a50>>
w_obj = <W_TypeObject 'ellipsis' at 0x14a4dcc8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x14a4dcc8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11cb4a50>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x14a4dcc8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11cb4a50>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11cb4a50>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11cb4a50>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 52.52 seconds ===========================
++ 02:57:18 starting module/cpyext/test/test_cell.py [54 started in total]
__ module/cpyext/test/test_capsule.py [51 done in total, somefailed=True] _____
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 0x0000000012fff718>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff912bfd38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001309e1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000bcbeda0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000bcbede0>]
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 0x000000001309e1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000bcbeda0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000bcbede0>]
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 0x00000000123d6110>
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 0x0000000013042760>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000013042760>
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 0x00000000123d4170>
key = (((True, True, True, False, False, 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 0x00000000123d4170>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000123d4170>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000123d4170>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000012e70560>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001348a250>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff8ff97dc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff8ff97e08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff8ff97e20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000000ff5b280>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000123d46e8>, <W_TypeObject 'GenericAlias' at 0x13a8e8a8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x140afb78>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x140afb78>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x140afb78>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x140afb78>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10f9fd50>>
w_obj = <W_TypeObject 'ellipsis' at 0x140afb78>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x140afb78>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10f9fd50>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x140afb78>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10f9fd50>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10f9fd50>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10f9fd50>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000000015714110>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff912bfd38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001309e1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000bcbeda0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000bcbede0>]
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 0x000000001309e1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000bcbeda0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000bcbede0>]
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 0x000000001608a598>
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 0x0000000015ff7b20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000015ff7b20>
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 0x0000000011df57f8>
key = (((True, True, True, False, False, 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 0x0000000011df57f8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000011df57f8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000011df57f8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000117e06a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001104cd78>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff8ff97dc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff8ff97e08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff8ff97e20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000000ff5b280>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000011df5d70>, <W_TypeObject 'GenericAlias' at 0x117c69f8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x13003d00>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x13003d00>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x13003d00>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x13003d00>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x125d4030>>
w_obj = <W_TypeObject 'ellipsis' at 0x13003d00>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x13003d00>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x125d4030>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x13003d00>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x125d4030>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x125d4030>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x125d4030>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000001390f4c0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff912bfd38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001309e1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000bcbeda0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000bcbede0>]
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 0x000000001309e1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000bcbeda0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000bcbede0>]
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 0x000000000f367970>
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 0x0000000015365ee0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000015365ee0>
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 0x0000000014b04a68>
key = (((True, True, True, False, False, 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 0x0000000014b04a68>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000014b04a68>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000014b04a68>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000015f1c8a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000147c7590>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff8ff97dc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff8ff97e08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff8ff97e20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000000ff5b280>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000014b04fe0>, <W_TypeObject 'GenericAlias' at 0x15e07440>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x160ef520>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x160ef520>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x160ef520>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x160ef520>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x12a3fb80>>
w_obj = <W_TypeObject 'ellipsis' at 0x160ef520>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x160ef520>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x12a3fb80>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x160ef520>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x12a3fb80>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x12a3fb80>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x12a3fb80>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 29.35 seconds ===========================
++ 02:57:28 starting module/cpyext/test/test_classobject.py [55 started in total]
__ module/cpyext/test/test_bytearrayobject.py [52 done in total, somefailed=True]
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 0x0000000039b95ad8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8de51d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000039eb8960>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000334d08e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000334d0920>]
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 0x0000000039eb8960>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000334d08e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000334d0920>]
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 0x0000000037842110>
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 0x000000003780e4e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000003780e4e0>
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 0x000000003780bf30>
key = (((True, True, True, False, False, 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 0x000000003780bf30>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000003780bf30>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000003780bf30>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000003aba1da0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000003adfe058>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff8f570dc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff8f570e08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff8f570e20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000003761e9c0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000003785c4f0>, <W_TypeObject 'GenericAlias' at 0x3b5713d0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3bb14720>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3bb14720>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3bb14720>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3bb14720>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3813dcb0>>
w_obj = <W_TypeObject 'ellipsis' at 0x3bb14720>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x3bb14720>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3813dcb0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x3bb14720>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3813dcb0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3813dcb0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3813dcb0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000003d016020>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8de51d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000039eb8960>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000334d08e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000334d0920>]
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 0x0000000039eb8960>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000334d08e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000334d0920>]
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 0x000000003cff6908>
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 0x000000003d00a020>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000003d00a020>
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 0x000000003d006058>
key = (((True, True, True, False, False, 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 0x000000003d006058>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000003d006058>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000003d006058>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000003aa31c20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000380ab9f0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff8f570dc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff8f570e08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff8f570e20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000003761e9c0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000003d0065d0>, <W_TypeObject 'GenericAlias' at 0x3ab6ea68>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3a017b78>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3a017b78>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3a017b78>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3a017b78>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x39fc6490>>
w_obj = <W_TypeObject 'ellipsis' at 0x3a017b78>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x3a017b78>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x39fc6490>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x3a017b78>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x39fc6490>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x39fc6490>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x39fc6490>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000003cc8c980>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8de51d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000039eb8960>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000334d08e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000334d0920>]
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 0x0000000039eb8960>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000334d08e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000334d0920>]
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 0x000000003a28c3e0>
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 0x000000003d2001e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000003d2001e0>
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 0x000000003d2027c8>
key = (((True, True, True, False, False, 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 0x000000003d2027c8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000003d2027c8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000003d2027c8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000003d356160>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000003d3ead40>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff8f570dc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff8f570e08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff8f570e20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000003761e9c0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000003d202d40>, <W_TypeObject 'GenericAlias' at 0x3d6bd050>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3d716b80>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3d716b80>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3d716b80>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3d716b80>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x381636e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x3d716b80>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x3d716b80>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x381636e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x3d716b80>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x381636e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x381636e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x381636e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000003e4aeae8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8de51d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000039eb8960>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000334d08e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000334d0920>]
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 0x0000000039eb8960>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000334d08e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000334d0920>]
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 0x000000003e88de48>
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 0x000000003e931d20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000003e931d20>
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 0x000000003e956e20>
key = (((True, True, True, False, False, 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 0x000000003e956e20>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000003e956e20>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000003e956e20>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000003e99d860>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000003eb2caa0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff8f570dc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff8f570e08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff8f570e20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000003761e9c0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000003e957398>, <W_TypeObject 'GenericAlias' at 0x3ee06988>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3ee94870>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3ee94870>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3ee94870>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3ee94870>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3841fc00>>
w_obj = <W_TypeObject 'ellipsis' at 0x3ee94870>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x3ee94870>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3841fc00>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x3ee94870>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3841fc00>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3841fc00>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3841fc00>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000003f86b3d0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8de51d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000039eb8960>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000334d08e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000334d0920>]
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 0x0000000039eb8960>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000334d08e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000334d0920>]
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 0x0000000037190ed0>
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 0x00000000379beae0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000379beae0>
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 0x0000000037addc20>
key = (((True, True, True, False, False, 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 0x0000000037addc20>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000037addc20>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000037addc20>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000037a67360>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000038fc4678>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff8f570dc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff8f570e08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff8f570e20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000003761e9c0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000037ae61e0>, <W_TypeObject 'GenericAlias' at 0x37d0c368>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x394bba98>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x394bba98>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x394bba98>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x394bba98>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3a47c470>>
w_obj = <W_TypeObject 'ellipsis' at 0x394bba98>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x394bba98>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3a47c470>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x394bba98>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3a47c470>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3a47c470>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3a47c470>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000000035652bd8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff8de51d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000039eb8960>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000334d08e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000334d0920>]
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 0x0000000039eb8960>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000334d08e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000334d0920>]
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 0x000000003a7b21b0>
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 0x000000003f47eaa0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000003f47eaa0>
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 0x000000003addc218>
key = (((True, True, True, False, False, 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 0x000000003addc218>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000003addc218>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000003addc218>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000003bf92e20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000003bfa6058>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff8f570dc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff8f570e08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff8f570e20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000003761e9c0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000003addc790>, <W_TypeObject 'GenericAlias' at 0x3d58e058>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3d415b08>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3d415b08>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3d415b08>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3d415b08>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3687f720>>
w_obj = <W_TypeObject 'ellipsis' at 0x3d415b08>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x3d415b08>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3687f720>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x3d415b08>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3687f720>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3687f720>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3687f720>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 52.63 seconds ===========================
++ 02:57:32 starting module/cpyext/test/test_codecs.py [56 started in total]
__ module/cpyext/test/test_cell.py [53 done in total, somefailed=True] ________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 0x00000000357b3790>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff9f821d70>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000038577760>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000315e2c60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000315e2ca0>]
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 0x0000000038577760>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000315e2c60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000315e2ca0>]
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 0x00000000386f3a38>
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 0x000000003687cce0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000003687cce0>
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 0x0000000037330020>
key = (((True, True, True, False, False, 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 0x0000000037330020>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000037330020>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000037330020>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000037af3f60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000003728d4b0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa0f40dc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffffa0f40e08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa0f40e20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000003576e410>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000037330598>, <W_TypeObject 'GenericAlias' at 0x38f94800>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x39537c90>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x39537c90>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x39537c90>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x39537c90>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x36b1b2c0>>
w_obj = <W_TypeObject 'ellipsis' at 0x39537c90>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x39537c90>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x36b1b2c0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x39537c90>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x36b1b2c0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x36b1b2c0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x36b1b2c0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 11.74 seconds ===========================
++ 02:57:51 starting module/cpyext/test/test_complexobject.py [57 started in total]
__ module/cpyext/test/test_classobject.py [54 done in total, somefailed=True] _
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 0x0000000032ee1da8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff9eb5bd38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000356f67a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002e784c60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002e784ca0>]
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 0x00000000356f67a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002e784c60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002e784ca0>]
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 0x00000000344f1b50>
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 0x000000003491a1a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000003491a1a0>
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 0x00000000344e6758>
key = (((True, True, True, False, False, 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 0x00000000344e6758>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000344e6758>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000344e6758>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000354c0120>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000003394fd38>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff9d833dc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff9d833e08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff9d833e20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000328bdc20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000344e6cd0>, <W_TypeObject 'GenericAlias' at 0x35ff39f0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x36662170>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x36662170>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x36662170>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x36662170>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x35611a90>>
w_obj = <W_TypeObject 'ellipsis' at 0x36662170>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x36662170>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x35611a90>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x36662170>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x35611a90>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x35611a90>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x35611a90>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000000037795448>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff9eb5bd38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000356f67a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002e784c60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002e784ca0>]
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 0x00000000356f67a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002e784c60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002e784ca0>]
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 0x0000000037c0b970>
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 0x0000000037b41fa0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000037b41fa0>
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 0x0000000037c0c218>
key = (((True, True, True, False, False, 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 0x0000000037c0c218>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000037c0c218>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000037c0c218>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000037ede060>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000037f91f30>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff9d833dc8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff9d833e08>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff9d833e20>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000328bdc20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000037c0c790>, <W_TypeObject 'GenericAlias' at 0x35e372b8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x324546e8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x324546e8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x324546e8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x324546e8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33d85fd0>>
w_obj = <W_TypeObject 'ellipsis' at 0x324546e8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x324546e8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33d85fd0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x324546e8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33d85fd0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33d85fd0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33d85fd0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 20.94 seconds ===========================
++ 02:58:13 starting module/cpyext/test/test_contextvars.py [58 started in total]
__ module/cpyext/test/test_codecs.py [55 done in total, somefailed=True] ______
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 0x2b5f4c10>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x29735b10>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000002dff8890>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffffae991d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002c780c60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000263a4be0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000263a4c20>]
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 0x000000002c780c60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000263a4be0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000263a4c20>]
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 0x000000002a827560>
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 0x000000002f130960>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000002f130960>
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 0x000000002f137ef8>
key = (((True, True, True, False, False, 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 0x000000002f137ef8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000002f137ef8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000002f137ef8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000002fbf7e20>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002f5adfa0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffad668dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffffad668e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffad668e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000002a67aa68>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000002f1964b8>, <W_TypeObject 'GenericAlias' at 0x2ffaea30>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3001ac98>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3001ac98>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3001ac98>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3001ac98>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2b87a0b0>>
w_obj = <W_TypeObject 'ellipsis' at 0x3001ac98>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x3001ac98>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2b87a0b0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x3001ac98>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2b87a0b0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2b87a0b0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2b87a0b0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 28.65 seconds ===========================
++ 02:58:23 starting module/cpyext/test/test_cpyext.py [59 started in total]
__ module/cpyext/test/test_contextvars.py [56 done in total, somefailed=True] _
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 0x000000001d2f7f10>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff9d235d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001c75c4a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000016878de0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000016878e20>]
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 0x000000001c75c4a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000016878de0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000016878e20>]
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 0x000000001db522a0>
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 0x000000001c6fe6a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000001c6fe6a0>
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 0x000000001ce95d38>
key = (((True, True, True, False, False, 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 0x000000001ce95d38>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000001ce95d38>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000001ce95d38>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000001e01ada0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001da63ec0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff9e953dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff9e953e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff9e953e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000001aa42b10>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000001c6ce2f8>, <W_TypeObject 'GenericAlias' at 0x1e1c6528>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e777478>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e777478>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e777478>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e777478>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b2cbcb0>>
w_obj = <W_TypeObject 'ellipsis' at 0x1e777478>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x1e777478>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b2cbcb0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x1e777478>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b2cbcb0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b2cbcb0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b2cbcb0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 11.62 seconds ===========================
++ 02:58:45 starting module/cpyext/test/test_datetime.py [60 started in total]
__ module/cpyext/test/test_complexobject.py [57 done in total, somefailed=True]
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 0x39888380>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000003df4a278>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffffa0c8bd38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000039f24020>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000344c2620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000344c2660>]
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 0x0000000039f24020>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000344c2620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000344c2660>]
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 0x000000003df91a38>
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 0x000000003df701e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000003df701e0>
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 0x000000003df38bb8>
key = (((True, True, True, False, False, 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 0x000000003df38bb8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000003df38bb8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000003df38bb8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000038a5f920>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000394c3168>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa23a9dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffffa23a9e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa23a9e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000003875a988>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000003df39130>, <W_TypeObject 'GenericAlias' at 0x38eb2e20>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x38a53478>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x38a53478>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x38a53478>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x38a53478>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3986d210>>
w_obj = <W_TypeObject 'ellipsis' at 0x38a53478>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x38a53478>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3986d210>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x38a53478>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3986d210>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3986d210>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3986d210>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000003d62dad8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffffa0c8bd38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000039f24020>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000344c2620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000344c2660>]
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 0x0000000039f24020>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000344c2620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000344c2660>]
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 0x0000000039c1ef20>
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 0x000000003e48a620>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000003e48a620>
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 0x000000003e48f4b0>
key = (((True, True, True, False, False, 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 0x000000003e48f4b0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000003e48f4b0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000003e48f4b0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000003e619ce0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000003e689280>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa23a9dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffffa23a9e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa23a9e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000003875a988>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000003e48fa28>, <W_TypeObject 'GenericAlias' at 0x3e9b4720>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3eabab48>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3eabab48>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3eabab48>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3eabab48>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3ad605c0>>
w_obj = <W_TypeObject 'ellipsis' at 0x3eabab48>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x3eabab48>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3ad605c0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x3eabab48>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3ad605c0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3ad605c0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3ad605c0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000003f76adb8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffffa0c8bd38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000039f24020>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000344c2620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000344c2660>]
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 0x0000000039f24020>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000344c2620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000344c2660>]
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 0x00000000401f45e8>
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 0x00000000401a0fa0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000401a0fa0>
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 0x00000000401b4db0>
key = (((True, True, True, False, False, 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 0x00000000401b4db0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000401b4db0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000401b4db0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000040233ee0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004038f4e8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa23a9dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffffa23a9e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa23a9e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000003875a988>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000401b5328>, <W_TypeObject 'GenericAlias' at 0x406201e0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4068d590>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4068d590>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4068d590>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4068d590>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x39866340>>
w_obj = <W_TypeObject 'ellipsis' at 0x4068d590>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4068d590>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x39866340>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4068d590>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x39866340>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x39866340>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x39866340>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000003aa712e0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffffa0c8bd38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000039f24020>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000344c2620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000344c2660>]
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 0x0000000039f24020>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000344c2620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000344c2660>]
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 0x0000000038a58890>
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 0x000000003a81b2a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000003a81b2a0>
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 0x000000003a8a0480>
key = (((True, True, True, False, False, 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 0x000000003a8a0480>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000003a8a0480>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000003a8a0480>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000003a9b5c60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000003ad82170>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa23a9dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffffa23a9e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa23a9e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000003875a988>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000003a8a09f8>, <W_TypeObject 'GenericAlias' at 0x3c194598>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3c20ee90>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3c20ee90>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3c20ee90>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3c20ee90>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3b8e1fa0>>
w_obj = <W_TypeObject 'ellipsis' at 0x3c20ee90>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x3c20ee90>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3b8e1fa0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x3c20ee90>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3b8e1fa0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3b8e1fa0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3b8e1fa0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000003885f2e0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffffa0c8bd38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000039f24020>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000344c2620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000344c2660>]
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 0x0000000039f24020>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000344c2620>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000344c2660>]
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 0x000000003acd8250>
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 0x000000003bc7c820>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000003bc7c820>
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 0x0000000039ed4aa0>
key = (((True, True, True, False, False, 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 0x0000000039ed4aa0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000039ed4aa0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000039ed4aa0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000003c18f520>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000003c21cb80>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa23a9dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffffa23a9e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa23a9e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000003875a988>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000039ed5018>, <W_TypeObject 'GenericAlias' at 0x3ec14528>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3dec22f8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3dec22f8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3dec22f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3dec22f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x37a2c300>>
w_obj = <W_TypeObject 'ellipsis' at 0x3dec22f8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x3dec22f8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x37a2c300>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x3dec22f8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x37a2c300>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x37a2c300>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x37a2c300>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 52.39 seconds ===========================
++ 02:59:03 starting module/cpyext/test/test_dictobject.py [61 started in total]
__ module/cpyext/test/test_bytesobject.py [58 done in total, somefailed=True] _
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 0x00000000455845c0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff80043d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000463dbce0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000003f472ce0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000003f472d20>]
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 0x00000000463dbce0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000003f472ce0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000003f472d20>]
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 0x00000000455582c8>
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 0x00000000464cdde0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000464cdde0>
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 0x00000000455872f0>
key = (((True, True, True, False, False, 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 0x00000000455872f0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000455872f0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000455872f0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000044fda420>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000044064528>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff81761dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff81761e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff81761e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000436d49f8>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000045587868>, <W_TypeObject 'GenericAlias' at 0x470b3a28>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x475eefe0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x475eefe0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x475eefe0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x475eefe0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46832cb0>>
w_obj = <W_TypeObject 'ellipsis' at 0x475eefe0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x475eefe0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46832cb0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x475eefe0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46832cb0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46832cb0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46832cb0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00000000495482f0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff80043d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000463dbce0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000003f472ce0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000003f472d20>]
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 0x00000000463dbce0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000003f472ce0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000003f472d20>]
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 0x00000000495cf0d8>
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 0x0000000049559660>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000049559660>
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 0x0000000044e9b130>
key = (((True, True, True, False, False, 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 0x0000000044e9b130>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000044e9b130>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000044e9b130>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000003f9395a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000043fd12f0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff81761dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff81761e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff81761e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000436d49f8>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000044e9b6a8>, <W_TypeObject 'GenericAlias' at 0x468af9b8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x46398608>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x46398608>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x46398608>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x46398608>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x42a8bb80>>
w_obj = <W_TypeObject 'ellipsis' at 0x46398608>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x46398608>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x42a8bb80>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x46398608>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x42a8bb80>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x42a8bb80>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x42a8bb80>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000004782c890>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff80043d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000463dbce0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000003f472ce0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000003f472d20>]
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 0x00000000463dbce0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000003f472ce0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000003f472d20>]
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 0x000000004464d628>
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 0x00000000489ecf60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000489ecf60>
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 0x00000000489f7be8>
key = (((True, True, True, False, False, 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 0x00000000489f7be8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000489f7be8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000489f7be8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004970b9e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000049782598>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff81761dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff81761e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff81761e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000436d49f8>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000488ce1a8>, <W_TypeObject 'GenericAlias' at 0x49b39408>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x49a90aa0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x49a90aa0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x49a90aa0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x49a90aa0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46442ab0>>
w_obj = <W_TypeObject 'ellipsis' at 0x49a90aa0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x49a90aa0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46442ab0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x49a90aa0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46442ab0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46442ab0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46442ab0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000004a18ff10>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff80043d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000463dbce0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000003f472ce0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000003f472d20>]
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 0x00000000463dbce0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000003f472ce0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000003f472d20>]
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 0x000000004b11f3d0>
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 0x000000004b0f4d20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004b0f4d20>
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 0x000000004b11c790>
key = (((True, True, True, False, False, 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 0x000000004b11c790>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004b11c790>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004b11c790>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004b4c4220>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004b509e88>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff81761dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff81761e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff81761e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000436d49f8>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000004b11cd08>, <W_TypeObject 'GenericAlias' at 0x4b82bb40>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b8e7de0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b8e7de0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b8e7de0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b8e7de0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45adb640>>
w_obj = <W_TypeObject 'ellipsis' at 0x4b8e7de0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4b8e7de0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45adb640>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4b8e7de0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45adb640>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45adb640>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45adb640>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00000000461498f8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff80043d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000463dbce0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000003f472ce0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000003f472d20>]
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 0x00000000463dbce0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000003f472ce0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000003f472d20>]
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 0x0000000043357178>
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 0x0000000044f0bee0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000044f0bee0>
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 0x0000000043da8b48>
key = (((True, True, True, False, False, 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 0x0000000043da8b48>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000043da8b48>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000043da8b48>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000045b21ae0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004538eb48>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff81761dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff81761e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff81761e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000436d49f8>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000043dd8020>, <W_TypeObject 'GenericAlias' at 0x45c9e560>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44b0d5c8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44b0d5c8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44b0d5c8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44b0d5c8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x40f53eb0>>
w_obj = <W_TypeObject 'ellipsis' at 0x44b0d5c8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x44b0d5c8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x40f53eb0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x44b0d5c8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x40f53eb0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x40f53eb0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x40f53eb0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00000000453a69f8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff80043d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000463dbce0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000003f472ce0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000003f472d20>]
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 0x00000000463dbce0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000003f472ce0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000003f472d20>]
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 0x0000000046628930>
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 0x0000000046f81020>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000046f81020>
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 0x000000004404eb48>
key = (((True, True, True, False, False, 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 0x000000004404eb48>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004404eb48>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004404eb48>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000047d86660>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000049a35b78>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff81761dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff81761e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff81761e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000436d49f8>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004404f0c0>, <W_TypeObject 'GenericAlias' at 0x4b71dd00>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48ad24b8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48ad24b8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48ad24b8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48ad24b8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x40cc29e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x48ad24b8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x48ad24b8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x40cc29e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x48ad24b8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x40cc29e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x40cc29e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x40cc29e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000000046420d40>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff80043d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000463dbce0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000003f472ce0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000003f472d20>]
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 0x00000000463dbce0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000003f472ce0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000003f472d20>]
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 0x000000004b666c28>
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 0x00000000489802a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000489802a0>
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 0x0000000048990058>
key = (((True, True, True, False, False, 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 0x0000000048990058>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000048990058>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000048990058>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000486e1ba0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000049f094b0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff81761dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff81761e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff81761e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000436d49f8>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000489905d0>, <W_TypeObject 'GenericAlias' at 0x47bfda28>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4ab6d9f0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4ab6d9f0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4ab6d9f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4ab6d9f0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45043ef0>>
w_obj = <W_TypeObject 'ellipsis' at 0x4ab6d9f0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4ab6d9f0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45043ef0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4ab6d9f0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45043ef0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45043ef0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x45043ef0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00000000497a4638>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff80043d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000463dbce0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000003f472ce0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000003f472d20>]
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 0x00000000463dbce0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000003f472ce0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000003f472d20>]
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 0x000000004af54ea8>
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 0x000000004af92360>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004af92360>
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 0x000000004af98608>
key = (((True, True, True, False, False, 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 0x000000004af98608>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000004af98608>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000004af98608>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004af93ce0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000046b15478>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff81761dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff81761e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff81761e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000436d49f8>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004af98b80>, <W_TypeObject 'GenericAlias' at 0x458733d0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x45c26838>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x45c26838>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x45c26838>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x45c26838>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x462e2820>>
w_obj = <W_TypeObject 'ellipsis' at 0x45c26838>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x45c26838>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x462e2820>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x45c26838>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x462e2820>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x462e2820>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x462e2820>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x00000000443cdf88>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff80043d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000463dbce0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000003f472ce0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000003f472d20>]
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 0x00000000463dbce0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000003f472ce0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000003f472d20>]
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 0x0000000045eba610>
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 0x000000004b14dba0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000004b14dba0>
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 0x0000000049684d08>
key = (((True, True, True, False, False, 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 0x0000000049684d08>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000049684d08>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000049684d08>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000004b17ea60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004a5d84f0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff81761dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff81761e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff81761e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000436d49f8>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000049685280>, <W_TypeObject 'GenericAlias' at 0x48fb12f0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4292ed08>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4292ed08>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4292ed08>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4292ed08>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46517520>>
w_obj = <W_TypeObject 'ellipsis' at 0x4292ed08>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x4292ed08>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46517520>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x4292ed08>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46517520>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46517520>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46517520>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x3fe68ee0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x444c90c0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x43b81bc0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x3f284fc0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x46475170>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x46a7b030>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x46a31440>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x462e4440>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x440f0390>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x4b3ed770>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x446e86c0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 151.95 seconds ==========================
++ 02:59:18 starting module/cpyext/test/test_eval.py [62 started in total]
__ module/cpyext/test/test_datetime.py [59 done in total, somefailed=True] ____
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 0x361dd4e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x34bf0980>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x31fa4ab0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x35534a00>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x3145f590>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x363189c0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x3b6623c0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x3150ad60>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x361f7700>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000000035a3fda8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff9eb07d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000036d80e60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002fb34ca0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002fb34ce0>]
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 0x0000000036d80e60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002fb34ca0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002fb34ce0>]
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 0x0000000038a0ca48>
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 0x000000003a831b20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000003a831b20>
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 0x000000003a86ec60>
key = (((True, True, True, False, False, 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 0x000000003a86ec60>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000003a86ec60>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000003a86ec60>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000003ac69720>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000003aa5f830>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa0226dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffffa0226e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa0226e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000033e0a0c8>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000003a86f1d8>, <W_TypeObject 'GenericAlias' at 0x38204138>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x39c96288>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x39c96288>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x39c96288>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x39c96288>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x348da520>>
w_obj = <W_TypeObject 'ellipsis' at 0x39c96288>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x39c96288>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x348da520>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x39c96288>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x348da520>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x348da520>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x348da520>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000003a5218f8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff9eb07d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000036d80e60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002fb34ca0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002fb34ce0>]
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 0x0000000036d80e60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002fb34ca0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002fb34ce0>]
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 0x000000003c91fdf8>
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 0x000000003c905ae0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000003c905ae0>
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 0x000000003c91ba60>
key = (((True, True, True, False, False, 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 0x000000003c91ba60>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000003c91ba60>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000003c91ba60>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000003c993720>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000003076dbb0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa0226dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffffa0226e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa0226e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000033e0a0c8>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000003c98a020>, <W_TypeObject 'GenericAlias' at 0x35f9b1d8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x36130838>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x36130838>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x36130838>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x36130838>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x36b29f20>>
w_obj = <W_TypeObject 'ellipsis' at 0x36130838>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x36130838>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x36b29f20>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x36130838>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x36b29f20>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x36b29f20>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x36b29f20>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000000038235448>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff9eb07d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000036d80e60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002fb34ca0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002fb34ce0>]
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 0x0000000036d80e60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002fb34ca0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002fb34ce0>]
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 0x0000000036193880>
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 0x000000003b292720>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000003b292720>
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 0x000000003a069d70>
key = (((True, True, True, False, False, 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 0x000000003a069d70>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000003a069d70>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000003a069d70>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000003b30ac60>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000382070c0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa0226dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffffa0226e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa0226e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000033e0a0c8>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000003a06a480>, <W_TypeObject 'GenericAlias' at 0x384442c0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3954ae90>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3954ae90>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3954ae90>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3954ae90>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3513b500>>
w_obj = <W_TypeObject 'ellipsis' at 0x3954ae90>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x3954ae90>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3513b500>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x3954ae90>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3513b500>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3513b500>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3513b500>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000000036a35cb8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff9eb07d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000036d80e60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002fb34ca0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002fb34ce0>]
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 0x0000000036d80e60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002fb34ca0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002fb34ce0>]
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 0x00000000376f59c0>
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 0x00000000395bd860>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000395bd860>
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 0x0000000039c19600>
key = (((True, True, True, False, False, 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 0x0000000039c19600>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000039c19600>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000039c19600>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000003c1f9ee0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000003942a950>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa0226dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffffa0226e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa0226e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000033e0a0c8>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000038f62218>, <W_TypeObject 'GenericAlias' at 0x3b52c0c8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x388bf980>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x388bf980>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x388bf980>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x388bf980>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x36993540>>
w_obj = <W_TypeObject 'ellipsis' at 0x388bf980>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x388bf980>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x36993540>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x388bf980>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x36993540>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x36993540>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x36993540>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000003bdc2458>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff9eb07d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000036d80e60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002fb34ca0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002fb34ce0>]
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 0x0000000036d80e60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002fb34ca0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002fb34ce0>]
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 0x00000000396446d8>
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 0x000000003c8e0420>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000003c8e0420>
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 0x000000003c8ecd40>
key = (((True, True, True, False, False, 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 0x000000003c8ecd40>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x000000003c8ecd40>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x000000003c8ecd40>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000003bb928a0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000003bb917f8>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa0226dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffffa0226e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa0226e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000033e0a0c8>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000003c8ed2b8>, <W_TypeObject 'GenericAlias' at 0x3c88bb78>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3c254b10>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3c254b10>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3c254b10>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3c254b10>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x32ec0b60>>
w_obj = <W_TypeObject 'ellipsis' at 0x3c254b10>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x3c254b10>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x32ec0b60>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x3c254b10>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x32ec0b60>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x32ec0b60>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x32ec0b60>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000000037289e20>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff9eb07d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000036d80e60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002fb34ca0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002fb34ce0>]
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 0x0000000036d80e60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002fb34ca0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002fb34ce0>]
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 0x0000000032109da8>
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 0x00000000370a67e0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000370a67e0>
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 0x00000000344a7750>
key = (((True, True, True, False, False, 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 0x00000000344a7750>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000344a7750>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000344a7750>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000371ba760>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000355aaf00>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa0226dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffffa0226e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa0226e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000033e0a0c8>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000344ae218>, <W_TypeObject 'GenericAlias' at 0x34472f00>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x34f58e20>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x34f58e20>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x34f58e20>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x34f58e20>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x361f71f0>>
w_obj = <W_TypeObject 'ellipsis' at 0x34f58e20>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x34f58e20>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x361f71f0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x34f58e20>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x361f71f0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x361f71f0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x361f71f0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000003aa00ea8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff9eb07d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000036d80e60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002fb34ca0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002fb34ce0>]
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 0x0000000036d80e60>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002fb34ca0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002fb34ce0>]
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 0x00000000364ec660>
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 0x000000003937c060>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000003937c060>
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 0x0000000039e51830>
key = (((True, True, True, False, False, 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 0x0000000039e51830>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000039e51830>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000039e51830>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000003937daa0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000003b507980>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa0226dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffffa0226e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffffa0226e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000033e0a0c8>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000039e51da8>, <W_TypeObject 'GenericAlias' at 0x393ed360>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x380782f8>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x380782f8>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x380782f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x380782f8>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x30c811e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x380782f8>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x380782f8>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x30c811e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x380782f8>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x30c811e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x30c811e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x30c811e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E 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 125.26 seconds ==========================
++ 03:01:10 starting module/cpyext/test/test_exception.py [63 started in total]
__ module/cpyext/test/test_dictobject.py [60 done in total, somefailed=True] __
============================= test session starts ==============================
platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /buildbot/slave/own-linux-aarch64/build/pytest.pyc
rootdir: /buildbot/slave/own-linux-aarch64/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 0x20178e70>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x1f161950>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x1d7bfe80>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x1abebbc0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x20524570>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x1f826cf0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x261e5d00>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x1b931bf0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000001fefeb60>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff85ac9d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001ffa7260>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001a2c6d60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001a2c6da0>]
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 0x000000001ffa7260>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001a2c6d60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001a2c6da0>]
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 0x0000000020fea890>
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 0x000000002292ea60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000002292ea60>
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 0x0000000023f5e100>
key = (((True, True, True, False, False, 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 0x0000000023f5e100>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000023f5e100>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000023f5e100>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000239ea560>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000260717c0>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff871e8dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff871e8e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff871e8e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000001e455478>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000023f5e678>, <W_TypeObject 'GenericAlias' at 0x265d2560>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x26bc3b08>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x26bc3b08>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x26bc3b08>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x26bc3b08>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1a0dd760>>
w_obj = <W_TypeObject 'ellipsis' at 0x26bc3b08>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x26bc3b08>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1a0dd760>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x26bc3b08>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1a0dd760>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1a0dd760>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1a0dd760>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000000024058a70>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff85ac9d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001ffa7260>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001a2c6d60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001a2c6da0>]
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 0x000000001ffa7260>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001a2c6d60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001a2c6da0>]
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 0x00000000235d5ec0>
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 0x000000002555a320>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x000000002555a320>
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 0x0000000022b95398>
key = (((True, True, True, False, False, 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 0x0000000022b95398>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000022b95398>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000022b95398>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000246108e0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000022fbe170>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff871e8dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff871e8e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff871e8e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000001e455478>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000022b95910>, <W_TypeObject 'GenericAlias' at 0x25ed44f0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25f1b638>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25f1b638>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25f1b638>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25f1b638>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x26bfe9e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x25f1b638>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x25f1b638>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x26bfe9e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x25f1b638>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x26bfe9e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x26bfe9e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x26bfe9e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000000024ca05c0>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff85ac9d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001ffa7260>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001a2c6d60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001a2c6da0>]
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 0x000000001ffa7260>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001a2c6d60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001a2c6da0>]
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 0x0000000024cb1308>
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 0x0000000024caeba0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000024caeba0>
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 0x00000000257679f0>
key = (((True, True, True, False, False, 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 0x00000000257679f0>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000257679f0>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000257679f0>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000025e94da0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001b812598>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff871e8dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff871e8e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff871e8e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000001e455478>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000025767f68>, <W_TypeObject 'GenericAlias' at 0x20b61ad0>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20f9d6e0>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20f9d6e0>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20f9d6e0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20f9d6e0>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f2ffb10>>
w_obj = <W_TypeObject 'ellipsis' at 0x20f9d6e0>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x20f9d6e0>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f2ffb10>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x20f9d6e0>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f2ffb10>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f2ffb10>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f2ffb10>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000000023c88bd8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff85ac9d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001ffa7260>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001a2c6d60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001a2c6da0>]
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 0x000000001ffa7260>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001a2c6d60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001a2c6da0>]
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 0x0000000020b00a20>
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 0x00000000224f3ae0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000224f3ae0>
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 0x0000000023564b48>
key = (((True, True, True, False, False, 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 0x0000000023564b48>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000023564b48>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000023564b48>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000246c7260>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000025fade18>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff871e8dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff871e8e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff871e8e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000001e455478>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000235650c0>, <W_TypeObject 'GenericAlias' at 0x25e72e90>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25371980>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25371980>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25371980>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25371980>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20337c40>>
w_obj = <W_TypeObject 'ellipsis' at 0x25371980>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x25371980>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20337c40>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x25371980>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20337c40>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20337c40>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20337c40>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x000000001aad4890>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff85ac9d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001ffa7260>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001a2c6d60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001a2c6da0>]
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 0x000000001ffa7260>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001a2c6d60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001a2c6da0>]
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 0x000000002240c6d8>
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 0x0000000022f6f5a0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000022f6f5a0>
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 0x0000000022bd6368>
key = (((True, True, True, False, False, 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 0x0000000022bd6368>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000022bd6368>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000022bd6368>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000261b1ae0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000026b86d08>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff871e8dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff871e8e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff871e8e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000001e455478>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000022bd68e0>, <W_TypeObject 'GenericAlias' at 0x24ea89f8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x23857a60>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x23857a60>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x23857a60>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x23857a60>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20bb50d0>>
w_obj = <W_TypeObject 'ellipsis' at 0x23857a60>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x23857a60>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20bb50d0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x23857a60>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20bb50d0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20bb50d0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20bb50d0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_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 0x0000000024ca1b50>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=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 0x0000ffff85ac9d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001ffa7260>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001a2c6d60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001a2c6da0>]
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 0x000000001ffa7260>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001a2c6d60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001a2c6da0>]
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 0x000000002719c160>
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 0x0000000025cc8a20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000025cc8a20>
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 0x0000000025ccdb78>
key = (((True, True, True, False, False, 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 0x0000000025ccdb78>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000025ccdb78>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000025ccdb78>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000025d6a620>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000025eccd78>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff871e8dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff871e8e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff871e8e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000001e455478>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000025d3a138>, <W_TypeObject 'GenericAlias' at 0x202d3980>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20477e88>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20477e88>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20477e88>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20477e88>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d780030>>
w_obj = <W_TypeObject 'ellipsis' at 0x20477e88>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x20477e88>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d780030>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x20477e88>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d780030>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d780030>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d780030>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError
______________ ERROR at setup of AppTestDictObject.test_typedict2 ______________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x0000000024523ad8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
../_pytest/runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_typedict2'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_typedict2'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
../_pytest/vendored_packages/pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x0000ffff85ac9d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001ffa7260>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001a2c6d60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001a2c6da0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_typedict2'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_typedict2'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
../_pytest/vendored_packages/pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001ffa7260>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001a2c6d60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001a2c6da0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_typedict2'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_typedict2'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
../_pytest/vendored_packages/pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_typedict2'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
../_pytest/vendored_packages/pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000000001f9f0b60>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._typedict2'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
../_pytest/vendored_packages/pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000ffff8574f320>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000ffff8574f320>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._typedict2'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
../_pytest/vendored_packages/pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_typedict2'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
../_pytest/vendored_packages/pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_typedict2'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x00000000234e6d78>
key = (((True, True, True, False, False, 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 0x00000000234e6d78>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000234e6d78>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000234e6d78>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x000000002479e420>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000257ea020>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff871e8dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff871e8e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff871e8e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000001e455478>, W_BoolObject(True), W_BoolObject(False), <p...<pypy.interpreter.special.Ellipsis object at 0x00000000234e72f0>, <W_TypeObject 'GenericAlias' at 0xffff85752218>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21cb1558>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21cb1558>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21cb1558>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21cb1558>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2050e690>>
w_obj = <W_TypeObject 'ellipsis' at 0x21cb1558>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x21cb1558>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2050e690>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x21cb1558>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2050e690>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2050e690>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2050e690>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError
______________ ERROR at setup of AppTestDictObject.test_advanced _______________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000000001cfff880>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
../_pytest/runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_advanced'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_advanced'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
../_pytest/vendored_packages/pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x0000ffff85ac9d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001ffa7260>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001a2c6d60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001a2c6da0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_advanced'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_advanced'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
../_pytest/vendored_packages/pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001ffa7260>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001a2c6d60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001a2c6da0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_advanced'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_advanced'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
../_pytest/vendored_packages/pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_advanced'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
../_pytest/vendored_packages/pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x0000000020840070>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_advanced'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
../_pytest/vendored_packages/pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000250a5d20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000250a5d20>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_advanced'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
../_pytest/vendored_packages/pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_advanced'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
../_pytest/vendored_packages/pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_advanced'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x00000000251072b8>
key = (((True, True, True, False, False, 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 0x00000000251072b8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000251072b8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000251072b8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000025ac5760>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000253b8e20>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff871e8dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff871e8e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff871e8e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000001e455478>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000025107830>, <W_TypeObject 'GenericAlias' at 0x2318c8a8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25466c28>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25466c28>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25466c28>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25466c28>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20bad9e0>>
w_obj = <W_TypeObject 'ellipsis' at 0x25466c28>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x25466c28>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20bad9e0>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x25466c28>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20bad9e0>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20bad9e0>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20bad9e0>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError
_____________ ERROR at setup of AppTestDictObject.test_subclassing _____________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x0000000025e55088>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
../_pytest/runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_subclassing'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_subclassing'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
../_pytest/vendored_packages/pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x0000ffff85ac9d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001ffa7260>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001a2c6d60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001a2c6da0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_subclassing'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_subclassing'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
../_pytest/vendored_packages/pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001ffa7260>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001a2c6d60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001a2c6da0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_subclassing'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_subclassing'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
../_pytest/vendored_packages/pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_subclassing'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
../_pytest/vendored_packages/pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x00000000251a7c18>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ubclassing'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
../_pytest/vendored_packages/pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000270eba60>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x00000000270eba60>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ubclassing'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
../_pytest/vendored_packages/pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_subclassing'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
../_pytest/vendored_packages/pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_subclassing'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x00000000259b8f70>
key = (((True, True, True, False, False, 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 0x00000000259b8f70>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x00000000259b8f70>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x00000000259b8f70>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x00000000276e4de0>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002775e870>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff871e8dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff871e8e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff871e8e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000001e455478>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000259b94e8>, <W_TypeObject 'GenericAlias' at 0x27a66d40>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25ec0870>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25ec0870>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25ec0870>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25ec0870>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f16df40>>
w_obj = <W_TypeObject 'ellipsis' at 0x25ec0870>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x25ec0870>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f16df40>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x25ec0870>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f16df40>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f16df40>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f16df40>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError
____________ ERROR at setup of AppTestDictObject.test_getitem_error ____________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000000001fe38ea8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
../_pytest/runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_getitem_error'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_getitem_error'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
../_pytest/vendored_packages/pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x0000ffff85ac9d38>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001ffa7260>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001a2c6d60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001a2c6da0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_getitem_error'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_getitem_error'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
../_pytest/vendored_packages/pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001ffa7260>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001a2c6d60>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001a2c6da0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_getitem_error'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_getitem_error'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
../_pytest/vendored_packages/pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_getitem_error'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
../_pytest/vendored_packages/pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x000000001e9c5b28>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...item_error'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
../_pytest/vendored_packages/pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000024a8abe0>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
../_pytest/vendored_packages/pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000000024a8abe0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...item_error'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
../_pytest/vendored_packages/pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_getitem_error'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
../_pytest/vendored_packages/pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_getitem_error'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:259:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]}
config = <rpython.config.config.Config object at 0x0000000024817980>
key = (((True, True, True, False, False, 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 0x0000000024817980>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool/pytest/objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000000024817980>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool/option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000000024817980>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter/baseobjspace.py:481:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
# final setup
> self.setup_builtin_modules()
objspace/std/objspace.py:118:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def setup_builtin_modules(self):
"only for initializing the space."
if self.config.objspace.usemodules.cpyext:
# Special-case this to have state.install_dll() called early, which
# is required to initialise sys on Windows.
from pypy.module.cpyext.state import State
> self.fromcache(State).build_api()
interpreter/baseobjspace.py:739:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.state.State instance at 0x0000000024f4e060>
def build_api(self):
"""NOT_RPYTHON
This function is called when at object space creation,
and drives the compilation of the cpyext library
"""
self.setup_rawrefcount()
from pypy.module.cpyext import api
if not self.space.config.translating:
> self.api_lib = str(api.build_bridge(self.space))
module/cpyext/state.py:128:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
def build_bridge(space):
"NOT_RPYTHON"
from rpython.translator.c.database import LowLevelDatabase
use_micronumpy = setup_micronumpy(space)
db = LowLevelDatabase()
prefix = 'cpyexttest'
generate_decls_and_callbacks(db, prefix=prefix)
# Structure declaration code
functions = []
members = []
structindex = {}
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
functions.append(func.get_ctypes_impl(name, db))
members.append(func.get_ptr_decl(name, db))
structindex[name] = len(structindex)
structmembers = '\n'.join(members)
struct_declaration_code = """\
struct PyPyAPI {
%(members)s
} _pypyAPI;
RPY_EXTERN struct PyPyAPI* pypyAPI;
struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
prologue = ("#include <Python.h>\n" +
"#include <structmember.h>\n" +
"#include <marshal.h>\n" +
"#include <pycore_namespace.h>\n" +
("#include <pypy_numpy.h>\n" if use_micronumpy else "") +
"#include <src/thread.c>\n")
code = (prologue +
struct_declaration_code +
'\n' +
'\n'.join(functions))
eci = build_eci(code, use_micronumpy, translating=False)
eci = eci.compile_shared_lib(
outputfilename=str(udir / "module_cache" / "pypyapi"),
symbolic=True)
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL)
# populate static data
builder = space.fromcache(State).builder = TestingObjBuilder()
from pypy.module import cpyext # for the eval() below
for name, (typ, expr) in GLOBALS.iteritems():
if '#' in name:
name, header = name.split('#')
assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*')
isptr = False
elif name.startswith('PyExc_'):
isptr = False
elif typ == 'PyDateTime_CAPI*':
isptr = True
else:
raise ValueError("Unknown static data: %s %s" % (typ, name))
w_obj = eval(expr)
INTERPLEVEL_API[name] = w_obj
mname = mangle_name(prefix, name)
if isptr:
assert typ == 'PyDateTime_CAPI*'
value = w_obj
ptr = ctypes.c_void_p.in_dll(bridge, mname)
ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value),
ctypes.c_void_p).value
elif typ in ('PyObject*', 'PyTypeObject*'):
if name.startswith('PyExc_'):
# we already have the pointer
in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll)
else:
# we have a structure, get its address
in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname)
py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll))
builder.prepare(py_obj, w_obj)
pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI')
# implement structure initialization code
for header, header_functions in FUNCTIONS_BY_HEADER.iteritems():
for name, func in header_functions.iteritems():
pypyAPI[structindex[name]] = ctypes.cast(
ll2ctypes.lltype2ctypes(func.get_llhelper(space)),
ctypes.c_void_p)
# we need to call this *after* the init code above, because it might
# indirectly call some functions which are attached to pypyAPI (e.g., we
# if do tuple_attach of the prebuilt empty tuple, we need to call
# _PyPy_Malloc)
> builder.attach_all(space)
module/cpyext/api.py:1468:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000234d2528>
space = StdObjSpace
def attach_all(self, space):
# this is RPython, called once in pypy-c when it imports cpyext
from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2
from pypy.module.cpyext.pyobject import track_static_reference
#
static_pyobjs = self.get_static_pyobjs()
static_objs_w = self.static_objs_w
# Static objects are immortal and exempt from the ob_pypy_link prefix: they
# are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather
# than rawrefcount-linked. See rawrefcount.rst.
for i in range(len(static_objs_w)):
track_static_reference(space, static_pyobjs[i], static_objs_w[i])
#
self.cpyext_type_init = []
attached_objs = []
for i in range(len(static_objs_w)):
> attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i)
module/cpyext/api.py:1535:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff871e8dd8>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0xffff871e8e18>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xffff871e8e30>>, ...]
static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000001e455478>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000024817ef8>, <W_TypeObject 'GenericAlias' at 0x24b849f8>, ...]
attached_objs = [0, 1, 2, 3], i = 4
def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i):
# Start at i but make sure all the base classes are already attached
from pypy.module.cpyext.pyobject import get_typedescr, make_ref
if i in attached_objs:
return
py_obj = static_pyobjs[i]
w_obj = static_objs_w[i]
w_base = None
# w_obj can be NotImplemented, which is not a W_TypeObject
if isinstance(w_obj, W_TypeObject):
bases_w = w_obj.bases_w
if bases_w:
w_base = find_best_base(bases_w)
if w_base:
try:
j = static_objs_w.index(w_base)
except ValueError:
j = -1
if j >=0 and j not in attached_objs:
attach_recursively(space, static_pyobjs, static_objs_w,
attached_objs, j)
w_type = space.type(w_obj)
typedescr = get_typedescr(w_type.layout.typedef)
py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr,
> make_ref(space, w_type))
module/cpyext/api.py:1497:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25697e50>
w_userdata = None, immortal = False
def make_ref(space, w_obj, w_userdata=None, immortal=False):
"""Turn the W_Root into a corresponding PyObject. You should
decref the returned PyObject later. Note that it is often the
case, but not guaranteed, that make_ref() returns always the
same PyObject for the same W_Root; for example, integers.
"""
assert not is_pyobj(w_obj)
if False and w_obj is not None and space.type(w_obj) is space.w_int:
# XXX: adapt for pypy3
state = space.fromcache(State)
intval = space.int_w(w_obj)
return state.ccall("PyLong_FromLong", intval)
> return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False)
module/cpyext/pyobject.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25697e50>
w_userdata = None, immortal = False
def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False):
> pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25697e50>
w_userdata = None, immortal = False
@jit.dont_look_inside
def as_pyobj(space, w_obj, w_userdata=None, immortal=False):
"""
Returns a 'PyObject *' representing the given interpreter object.
This doesn't give a new reference, but the returned 'PyObject *'
is valid at least as long as 'w_obj' is. **To be safe, you should
use keepalive_until_here(w_obj) some time later.** In case of
doubt, use the safer make_ref().
"""
assert not is_pyobj(w_obj)
if w_obj is not None:
py_obj = w_obj._cpyext_as_pyobj(space)
if not py_obj:
> py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal)
module/cpyext/pyobject.py:445:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25697e50>
w_userdata = None, immortal = False
@jit.dont_look_inside
def create_ref(space, w_obj, w_userdata=None, immortal=False):
"""
Allocates a PyObject, and fills its fields with info from the given
interpreter object.
"""
w_type = space.type(w_obj)
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if space.is_w(w_type, space.w_text):
# These PyUnicodeObjects will always take the compact form
# since they come from uint8-encoded strings, so we must
# override the default tp_itemsize (see also unicode_alloc)
# Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj?
itemsize = 1
elif space.is_w(w_type, space.w_type):
# Subclasses of "type" (which has space for PyMemberDef) do not
# need space for tp_member like heap types do
itemsize = 0
else:
itemsize = pytype.c_tp_itemsize
if itemsize != 0 or space.issubtype_w(w_type, space.w_list):
# PyBytesObject, compact PyUnicodeObject and subclasses
try:
# Can cause infinite recursion if w_obj.__len__ is a c function
# so the call will try to convert w_obj to a pyobj via create_ref
from pypy.objspace.std.listobject import W_ListObject
if isinstance(w_obj, W_ListObject):
itemcount = w_obj.length()
else:
itemcount = space.len_w(w_obj)
except OperationError as e:
if e.match(space, space.w_TypeError):
# issue 4013: is this correct?
itemcount = 0
# raise oefmt(space.w_SystemError,
# "cpyext: Failure to allocate '%N' (with a non-zero "
# "tp_itemsize) when len(obj) cannot be calculated",
# w_type)
else:
raise
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal)
> track_reference(space, py_obj, w_obj)
module/cpyext/pyobject.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1a69cb80>>
w_obj = <W_TypeObject 'ellipsis' at 0x25697e50>
def track_reference(space, py_obj, w_obj):
"""
Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj.
A foreign py_obj (below the tag, no prefix) is left unlinked.
"""
# XXX looks like a PyObject_GC_TRACK
if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY:
> w_obj._cpyext_attach_pyobj(space, py_obj)
module/cpyext/pyobject.py:375:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <W_TypeObject 'ellipsis' at 0x25697e50>, space = StdObjSpace
py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1a69cb80>>
def _cpyext_attach_pyobj(self, space, py_obj):
self._cpy_ref = py_obj
> rawrefcount.create_link_pypy(self, py_obj)
module/cpyext/pyobject.py:132:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = <W_TypeObject 'ellipsis' at 0x25697e50>
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1a69cb80>>
@not_rpython
def create_link_pypy(p, ob):
"a link where the PyPy object contains some or all the data"
#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob)
assert p not in _pypy2ob
assert ob._obj not in _pypy2ob_rev
> assert not _ob_link_get(ob)
../rpython/rlib/rawrefcount.py:187:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1a69cb80>>
def _ob_link_get(ob):
> return ob.c_ob_pypy_link
../rpython/rlib/rawrefcount.py:102:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1a69cb80>>
field_name = 'c_ob_pypy_link'
def __getattr__(self, field_name): # ! can only return basic or ptr !
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = self._obj._getattr(field_name)
return self._expose(field_name, o)
try:
return self._lookup_adtmeth(field_name)
except AttributeError:
raise AttributeError("%r instance has no field %r" % (self._T,
> field_name))
E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'
../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError
______________ ERROR at setup of AppTestDictObject.test_contains _______________
self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'>
func = <function <lambda> at 0x000000002471b9e8>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
../_pytest/runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
../_pytest/runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_contains'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'tes
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=4220.026014